@cedarjs/auth-supabase-middleware 5.0.3 → 5.0.4-next.167

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-supabase-middleware",
3
- "version": "5.0.3",
3
+ "version": "5.0.4-next.167",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -10,27 +10,21 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
- "import": {
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
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
- "build:types-cjs": "tsc --build --verbose ./tsconfig.cjs.json",
34
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",
@@ -38,22 +32,18 @@
38
32
  "test:watch": "vitest watch"
39
33
  },
40
34
  "dependencies": {
41
- "@cedarjs/auth-supabase-api": "5.0.3",
42
- "@cedarjs/web": "5.0.3",
43
- "@supabase/ssr": "0.12.0"
35
+ "@cedarjs/auth-supabase-api": "5.0.4-next.167",
36
+ "@cedarjs/web": "5.0.4-next.167"
44
37
  },
45
38
  "devDependencies": {
46
- "@arethetypeswrong/cli": "0.18.4",
47
- "@cedarjs/api": "5.0.3",
48
- "@cedarjs/auth": "5.0.3",
49
- "@cedarjs/framework-tools": "5.0.3",
50
- "@cedarjs/graphql-server": "5.0.3",
51
- "@types/aws-lambda": "8.10.162",
39
+ "@cedarjs/api": "5.0.4-next.167",
40
+ "@cedarjs/auth": "5.0.4-next.167",
41
+ "@cedarjs/framework-tools": "5.0.4-next.167",
42
+ "@cedarjs/graphql-server": "5.0.4-next.167",
52
43
  "concurrently": "9.2.4",
53
- "publint": "0.3.21",
54
- "ts-toolbelt": "9.6.0",
44
+ "publint": "0.3.22",
55
45
  "typescript": "5.9.3",
56
- "vitest": "3.2.6"
46
+ "vitest": "4.1.10"
57
47
  },
58
48
  "engines": {
59
49
  "node": ">=24"
@@ -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
- });
@@ -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
@@ -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 index_exports = {};
20
- __export(index_exports, {
21
- default: () => index_default
22
- });
23
- module.exports = __toCommonJS(index_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, request: 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 index_default = initSupabaseAuthMiddleware;
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,7 +0,0 @@
1
- import type { MiddlewareRequest, MiddlewareResponse } from '@cedarjs/web/middleware';
2
- /**
3
- * Clear the Supabase and auth cookies from the request and response
4
- * and clear the auth context
5
- */
6
- export declare const clearAuthState: (req: MiddlewareRequest, res: MiddlewareResponse) => void;
7
- //# sourceMappingURL=util.d.ts.map
@@ -1 +0,0 @@
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/cjs/util.js DELETED
@@ -1,42 +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
- });
23
- module.exports = __toCommonJS(util_exports);
24
- var import_api = require("@cedarjs/api");
25
- const clearAuthState = (req, res) => {
26
- req.serverAuthState.clear();
27
- const cookieHeader = req.headers.get("cookie");
28
- if (cookieHeader) {
29
- const cookies = cookieHeader.split(";").map((c) => c.trim().split("=")[0]);
30
- const supabaseCookie = cookies.find(
31
- (name) => /^sb-.*-auth-token$/.test(name)
32
- );
33
- if (supabaseCookie) {
34
- res.cookies.unset(supabaseCookie);
35
- }
36
- }
37
- res.cookies.unset(import_api.AUTH_PROVIDER_HEADER);
38
- };
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- clearAuthState
42
- });