@cedarjs/auth-supabase-middleware 9.0.0-canary.1784 → 9.0.0-canary.3124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/util.d.ts +0 -8
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +10 -39
- package/package.json +18 -26
- package/LICENSE +0 -21
- package/dist/cjs/defaultGetRoles.d.ts +0 -41
- package/dist/cjs/defaultGetRoles.d.ts.map +0 -1
- package/dist/cjs/defaultGetRoles.js +0 -39
- package/dist/cjs/index.d.ts +0 -12
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -74
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/util.d.ts +0 -15
- package/dist/cjs/util.d.ts.map +0 -1
- package/dist/cjs/util.js +0 -72
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ const initSupabaseAuthMiddleware = ({
|
|
|
22
22
|
const currentUser = await getCurrentUser(
|
|
23
23
|
decoded,
|
|
24
24
|
{ type, token: cookieHeader, schema: "cookie" },
|
|
25
|
-
{ event: req }
|
|
25
|
+
{ event: req, request: req }
|
|
26
26
|
);
|
|
27
27
|
if (req.url.includes(`/middleware/supabase/currentUser`)) {
|
|
28
28
|
res.body = // Not sure how currentUser can be string.... but types say so
|
|
@@ -48,7 +48,7 @@ const initSupabaseAuthMiddleware = ({
|
|
|
48
48
|
};
|
|
49
49
|
return [middleware, "*"];
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var index_default = initSupabaseAuthMiddleware;
|
|
52
52
|
export {
|
|
53
|
-
|
|
53
|
+
index_default as default
|
|
54
54
|
};
|
package/dist/util.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import type { MiddlewareRequest, MiddlewareResponse } from '@cedarjs/web/middleware';
|
|
2
|
-
/**
|
|
3
|
-
* Creates Supabase Server Client used to get the session cookie (only)
|
|
4
|
-
* from a given collection of auth cookies
|
|
5
|
-
*/
|
|
6
|
-
export declare const createSupabaseServerClient: (req: MiddlewareRequest, res: MiddlewareResponse) => {
|
|
7
|
-
cookieName: null;
|
|
8
|
-
supabase: import("@supabase/supabase-js/dist/index.cjs").SupabaseClient<any, "public", "public", any, any>;
|
|
9
|
-
};
|
|
10
2
|
/**
|
|
11
3
|
* Clear the Supabase and auth cookies from the request and response
|
|
12
4
|
* and clear the auth context
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yBAAyB,CAAA;AAEhC;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,SAuBxB,CAAA"}
|
package/dist/util.js
CHANGED
|
@@ -1,47 +1,18 @@
|
|
|
1
|
-
import { createServerClient } from "@supabase/ssr";
|
|
2
1
|
import { AUTH_PROVIDER_HEADER } from "@cedarjs/api";
|
|
3
|
-
import { throwSupabaseSettingsError } from "@cedarjs/auth-supabase-api";
|
|
4
|
-
const createSupabaseServerClient = (req, res) => {
|
|
5
|
-
let cookieName = null;
|
|
6
|
-
if (!process.env.SUPABASE_URL) {
|
|
7
|
-
throwSupabaseSettingsError("SUPABASE_URL");
|
|
8
|
-
}
|
|
9
|
-
if (!process.env.SUPABASE_KEY) {
|
|
10
|
-
throwSupabaseSettingsError("SUPABASE_KEY");
|
|
11
|
-
}
|
|
12
|
-
const supabase = createServerClient(
|
|
13
|
-
process.env.SUPABASE_URL || "",
|
|
14
|
-
process.env.SUPABASE_KEY || "",
|
|
15
|
-
{
|
|
16
|
-
cookies: {
|
|
17
|
-
get(name) {
|
|
18
|
-
cookieName = name;
|
|
19
|
-
return req.cookies.get(name)?.valueOf();
|
|
20
|
-
},
|
|
21
|
-
set(name, value, options) {
|
|
22
|
-
cookieName = name;
|
|
23
|
-
req.cookies.set(name, value, options);
|
|
24
|
-
res.cookies.set(name, value, options);
|
|
25
|
-
},
|
|
26
|
-
remove(name, options) {
|
|
27
|
-
cookieName = name;
|
|
28
|
-
req.cookies.set(name, "", options);
|
|
29
|
-
res.cookies.set(name, "", options);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
return { cookieName, supabase };
|
|
35
|
-
};
|
|
36
2
|
const clearAuthState = (req, res) => {
|
|
37
3
|
req.serverAuthState.clear();
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
|
|
4
|
+
const cookieHeader = req.headers.get("cookie");
|
|
5
|
+
if (cookieHeader) {
|
|
6
|
+
const cookies = cookieHeader.split(";").map((c) => c.trim().split("=")[0]);
|
|
7
|
+
const supabaseCookie = cookies.find(
|
|
8
|
+
(name) => /^sb-.*-auth-token$/.test(name)
|
|
9
|
+
);
|
|
10
|
+
if (supabaseCookie) {
|
|
11
|
+
res.cookies.unset(supabaseCookie);
|
|
12
|
+
}
|
|
41
13
|
}
|
|
42
14
|
res.cookies.unset(AUTH_PROVIDER_HEADER);
|
|
43
15
|
};
|
|
44
16
|
export {
|
|
45
|
-
clearAuthState
|
|
46
|
-
createSupabaseServerClient
|
|
17
|
+
clearAuthState
|
|
47
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-supabase-middleware",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3124",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -10,54 +10,46 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
13
|
+
"default": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
|
-
},
|
|
17
|
-
"require": {
|
|
18
|
-
"types": "./dist/cjs/index.d.ts",
|
|
19
|
-
"default": "./dist/cjs/index.js"
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
18
|
},
|
|
23
19
|
"main": "./dist/index.js",
|
|
24
20
|
"types": "./dist/index.d.ts",
|
|
25
21
|
"files": [
|
|
26
|
-
"dist"
|
|
27
|
-
"cjsWrappers"
|
|
22
|
+
"dist"
|
|
28
23
|
],
|
|
29
24
|
"scripts": {
|
|
30
|
-
"build": "
|
|
25
|
+
"build": "node ./build.mts",
|
|
31
26
|
"build:pack": "yarn pack -o cedarjs-auth-supabase-middleware.tgz",
|
|
32
27
|
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
33
|
-
"
|
|
34
|
-
"check:attw": "yarn attw -P",
|
|
28
|
+
"check:attw": "yarn cedar-fwtools-attw",
|
|
35
29
|
"check:package": "concurrently npm:check:attw yarn:publint",
|
|
36
30
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
37
31
|
"test": "vitest run",
|
|
38
32
|
"test:watch": "vitest watch"
|
|
39
33
|
},
|
|
40
34
|
"dependencies": {
|
|
41
|
-
"@cedarjs/auth-supabase-api": "9.0.0-canary.
|
|
42
|
-
"@cedarjs/web": "9.0.0-canary.
|
|
43
|
-
"@supabase/ssr": "0.8.0"
|
|
35
|
+
"@cedarjs/auth-supabase-api": "9.0.0-canary.3124",
|
|
36
|
+
"@cedarjs/web": "9.0.0-canary.3124"
|
|
44
37
|
},
|
|
45
38
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@cedarjs/
|
|
48
|
-
"@cedarjs/
|
|
49
|
-
"@cedarjs/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"concurrently": "9.2.1",
|
|
53
|
-
"publint": "0.3.17",
|
|
54
|
-
"ts-toolbelt": "9.6.0",
|
|
55
|
-
"tsx": "4.21.0",
|
|
39
|
+
"@cedarjs/api": "9.0.0-canary.3124",
|
|
40
|
+
"@cedarjs/auth": "9.0.0-canary.3124",
|
|
41
|
+
"@cedarjs/framework-tools": "9.0.0-canary.3124",
|
|
42
|
+
"@cedarjs/graphql-server": "9.0.0-canary.3124",
|
|
43
|
+
"concurrently": "9.2.4",
|
|
44
|
+
"publint": "0.3.24",
|
|
56
45
|
"typescript": "5.9.3",
|
|
57
|
-
"vitest": "
|
|
46
|
+
"vitest": "4.1.11"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=24"
|
|
58
50
|
},
|
|
59
51
|
"publishConfig": {
|
|
60
52
|
"access": "public"
|
|
61
53
|
},
|
|
62
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
|
|
63
55
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Cedar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Currently the supabase auth decoder returns something like this:
|
|
3
|
-
{
|
|
4
|
-
"aud": "authenticated",
|
|
5
|
-
"exp": 1716806712,
|
|
6
|
-
"iat": 1716803112,
|
|
7
|
-
"iss": "https://bubnfbrfzfdryapcuybr.supabase.co/auth/v1",
|
|
8
|
-
"sub": "75fd8091-e0a7-4e7d-8a8d-138d0eb3ca5a",
|
|
9
|
-
"email": "dannychoudhury+1@gmail.com",
|
|
10
|
-
"phone": "",
|
|
11
|
-
"app_metadata": {
|
|
12
|
-
"provider": "email",
|
|
13
|
-
"providers": [
|
|
14
|
-
"email"
|
|
15
|
-
],
|
|
16
|
-
"roles": "admin" <-- this the role we're looking for
|
|
17
|
-
},
|
|
18
|
-
"user_metadata": {
|
|
19
|
-
"full-name": "Danny Choudhury 1"
|
|
20
|
-
},
|
|
21
|
-
"role": "authenticated", <-- this is the role supabase sets
|
|
22
|
-
"aal": "aal1",
|
|
23
|
-
"amr": [
|
|
24
|
-
{
|
|
25
|
-
"method": "password",
|
|
26
|
-
"timestamp": 1716803107
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"session_id": "39b4ae31-c57a-4ac1-8f01-e9d6ccbd9365",
|
|
30
|
-
"is_anonymous": false
|
|
31
|
-
}
|
|
32
|
-
*/
|
|
33
|
-
interface PartialSupabaseDecoded {
|
|
34
|
-
app_metadata: {
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
roles?: string | undefined;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export declare const defaultGetRoles: (decoded: PartialSupabaseDecoded) => string[];
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=defaultGetRoles.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultGetRoles.d.ts","sourceRoot":"","sources":["../../src/defaultGetRoles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,UAAU,sBAAsB;IAC9B,YAAY,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;QACtB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC3B,CAAA;CACF;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,sBAAsB,KAAG,MAAM,EAYvE,CAAA"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var defaultGetRoles_exports = {};
|
|
20
|
-
__export(defaultGetRoles_exports, {
|
|
21
|
-
defaultGetRoles: () => defaultGetRoles
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(defaultGetRoles_exports);
|
|
24
|
-
const defaultGetRoles = (decoded) => {
|
|
25
|
-
try {
|
|
26
|
-
const roles = decoded?.app_metadata?.roles;
|
|
27
|
-
if (Array.isArray(roles)) {
|
|
28
|
-
return roles;
|
|
29
|
-
} else {
|
|
30
|
-
return roles ? [roles] : [];
|
|
31
|
-
}
|
|
32
|
-
} catch {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
defaultGetRoles
|
|
39
|
-
});
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { GetCurrentUser } from '@cedarjs/graphql-server';
|
|
2
|
-
import type { Middleware } from '@cedarjs/web/middleware';
|
|
3
|
-
export interface SupabaseAuthMiddlewareOptions {
|
|
4
|
-
getCurrentUser: GetCurrentUser;
|
|
5
|
-
getRoles?: (decoded: any) => string[];
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Create Supabase Auth Middleware that sets the `serverAuthState` based on the Supabase cookie.
|
|
9
|
-
*/
|
|
10
|
-
declare const initSupabaseAuthMiddleware: ({ getCurrentUser, getRoles, }: SupabaseAuthMiddlewareOptions) => [Middleware, "*"];
|
|
11
|
-
export default initSupabaseAuthMiddleware;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,yBAAyB,CAAA;AAIhC,MAAM,WAAW,6BAA6B;IAC5C,cAAc,EAAE,cAAc,CAAA;IAC9B,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,EAAE,CAAA;CACtC;AAED;;GAEG;AACH,QAAA,MAAM,0BAA0B,GAAI,+BAGjC,6BAA6B,KAAG,CAAC,UAAU,EAAE,GAAG,CAmElD,CAAA;AACD,eAAe,0BAA0B,CAAA"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var src_exports = {};
|
|
20
|
-
__export(src_exports, {
|
|
21
|
-
default: () => src_default
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(src_exports);
|
|
24
|
-
var import_api = require("@cedarjs/api");
|
|
25
|
-
var import_auth_supabase_api = require("@cedarjs/auth-supabase-api");
|
|
26
|
-
var import_util = require("./util.js");
|
|
27
|
-
const initSupabaseAuthMiddleware = ({
|
|
28
|
-
getCurrentUser,
|
|
29
|
-
getRoles
|
|
30
|
-
}) => {
|
|
31
|
-
const middleware = async (req, res) => {
|
|
32
|
-
const type = "supabase";
|
|
33
|
-
const cookieHeader = req.headers.get("cookie");
|
|
34
|
-
if (!cookieHeader) {
|
|
35
|
-
return res;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const authProviderCookie = req.cookies.get(import_api.AUTH_PROVIDER_HEADER);
|
|
39
|
-
if (!authProviderCookie || authProviderCookie !== type) {
|
|
40
|
-
return res;
|
|
41
|
-
}
|
|
42
|
-
const decoded = await (0, import_auth_supabase_api.authDecoder)(cookieHeader, type, {
|
|
43
|
-
event: req
|
|
44
|
-
});
|
|
45
|
-
const currentUser = await getCurrentUser(
|
|
46
|
-
decoded,
|
|
47
|
-
{ type, token: cookieHeader, schema: "cookie" },
|
|
48
|
-
{ event: req }
|
|
49
|
-
);
|
|
50
|
-
if (req.url.includes(`/middleware/supabase/currentUser`)) {
|
|
51
|
-
res.body = // Not sure how currentUser can be string.... but types say so
|
|
52
|
-
typeof currentUser === "string" ? currentUser : JSON.stringify({ currentUser });
|
|
53
|
-
return res;
|
|
54
|
-
}
|
|
55
|
-
const userMetadata = typeof currentUser === "string" ? null : currentUser?.["user_metadata"];
|
|
56
|
-
req.serverAuthState.set({
|
|
57
|
-
currentUser,
|
|
58
|
-
loading: false,
|
|
59
|
-
isAuthenticated: !!currentUser,
|
|
60
|
-
hasError: false,
|
|
61
|
-
userMetadata: userMetadata || currentUser,
|
|
62
|
-
cookieHeader,
|
|
63
|
-
roles: getRoles ? getRoles(decoded) : []
|
|
64
|
-
});
|
|
65
|
-
} catch (e) {
|
|
66
|
-
console.error("Error in Supabase Auth Middleware", e);
|
|
67
|
-
(0, import_util.clearAuthState)(req, res);
|
|
68
|
-
return res;
|
|
69
|
-
}
|
|
70
|
-
return res;
|
|
71
|
-
};
|
|
72
|
-
return [middleware, "*"];
|
|
73
|
-
};
|
|
74
|
-
var src_default = initSupabaseAuthMiddleware;
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/dist/cjs/util.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { MiddlewareRequest, MiddlewareResponse } from '@cedarjs/web/middleware';
|
|
2
|
-
/**
|
|
3
|
-
* Creates Supabase Server Client used to get the session cookie (only)
|
|
4
|
-
* from a given collection of auth cookies
|
|
5
|
-
*/
|
|
6
|
-
export declare const createSupabaseServerClient: (req: MiddlewareRequest, res: MiddlewareResponse) => {
|
|
7
|
-
cookieName: null;
|
|
8
|
-
supabase: import("@supabase/supabase-js").SupabaseClient<any, "public", "public", any, any>;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Clear the Supabase and auth cookies from the request and response
|
|
12
|
-
* and clear the auth context
|
|
13
|
-
*/
|
|
14
|
-
export declare const clearAuthState: (req: MiddlewareRequest, res: MiddlewareResponse) => void;
|
|
15
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/cjs/util.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yBAAyB,CAAA;AAChC;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GACrC,KAAK,iBAAiB,EACtB,KAAK,kBAAkB;;;CAoCxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,SAgBxB,CAAA"}
|
package/dist/cjs/util.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var util_exports = {};
|
|
20
|
-
__export(util_exports, {
|
|
21
|
-
clearAuthState: () => clearAuthState,
|
|
22
|
-
createSupabaseServerClient: () => createSupabaseServerClient
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(util_exports);
|
|
25
|
-
var import_ssr = require("@supabase/ssr");
|
|
26
|
-
var import_api = require("@cedarjs/api");
|
|
27
|
-
var import_auth_supabase_api = require("@cedarjs/auth-supabase-api");
|
|
28
|
-
const createSupabaseServerClient = (req, res) => {
|
|
29
|
-
let cookieName = null;
|
|
30
|
-
if (!process.env.SUPABASE_URL) {
|
|
31
|
-
(0, import_auth_supabase_api.throwSupabaseSettingsError)("SUPABASE_URL");
|
|
32
|
-
}
|
|
33
|
-
if (!process.env.SUPABASE_KEY) {
|
|
34
|
-
(0, import_auth_supabase_api.throwSupabaseSettingsError)("SUPABASE_KEY");
|
|
35
|
-
}
|
|
36
|
-
const supabase = (0, import_ssr.createServerClient)(
|
|
37
|
-
process.env.SUPABASE_URL || "",
|
|
38
|
-
process.env.SUPABASE_KEY || "",
|
|
39
|
-
{
|
|
40
|
-
cookies: {
|
|
41
|
-
get(name) {
|
|
42
|
-
cookieName = name;
|
|
43
|
-
return req.cookies.get(name)?.valueOf();
|
|
44
|
-
},
|
|
45
|
-
set(name, value, options) {
|
|
46
|
-
cookieName = name;
|
|
47
|
-
req.cookies.set(name, value, options);
|
|
48
|
-
res.cookies.set(name, value, options);
|
|
49
|
-
},
|
|
50
|
-
remove(name, options) {
|
|
51
|
-
cookieName = name;
|
|
52
|
-
req.cookies.set(name, "", options);
|
|
53
|
-
res.cookies.set(name, "", options);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
return { cookieName, supabase };
|
|
59
|
-
};
|
|
60
|
-
const clearAuthState = (req, res) => {
|
|
61
|
-
req.serverAuthState.clear();
|
|
62
|
-
const { cookieName } = createSupabaseServerClient(req, res);
|
|
63
|
-
if (cookieName) {
|
|
64
|
-
res.cookies.unset(cookieName);
|
|
65
|
-
}
|
|
66
|
-
res.cookies.unset(import_api.AUTH_PROVIDER_HEADER);
|
|
67
|
-
};
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
clearAuthState,
|
|
71
|
-
createSupabaseServerClient
|
|
72
|
-
});
|