@cedarjs/auth-supabase-middleware 5.0.2-rc.5 → 6.0.0-canary.2616

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.
@@ -1,4 +1,12 @@
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").SupabaseClient<any, "public", "public", any, any>;
9
+ };
2
10
  /**
3
11
  * Clear the Supabase and auth cookies from the request and response
4
12
  * and clear the auth context
@@ -1 +1 @@
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"}
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 CHANGED
@@ -18,25 +18,55 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var util_exports = {};
20
20
  __export(util_exports, {
21
- clearAuthState: () => clearAuthState
21
+ clearAuthState: () => clearAuthState,
22
+ createSupabaseServerClient: () => createSupabaseServerClient
22
23
  });
23
24
  module.exports = __toCommonJS(util_exports);
25
+ var import_ssr = require("@supabase/ssr");
24
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
+ };
25
60
  const clearAuthState = (req, res) => {
26
61
  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
- }
62
+ const { cookieName } = createSupabaseServerClient(req, res);
63
+ if (cookieName) {
64
+ res.cookies.unset(cookieName);
36
65
  }
37
66
  res.cookies.unset(import_api.AUTH_PROVIDER_HEADER);
38
67
  };
39
68
  // Annotate the CommonJS export names for ESM import in node:
40
69
  0 && (module.exports = {
41
- clearAuthState
70
+ clearAuthState,
71
+ createSupabaseServerClient
42
72
  });
package/dist/util.d.ts CHANGED
@@ -1,4 +1,12 @@
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
+ };
2
10
  /**
3
11
  * Clear the Supabase and auth cookies from the request and response
4
12
  * and clear the auth context
@@ -1 +1 @@
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"}
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/util.js CHANGED
@@ -1,18 +1,47 @@
1
+ import { createServerClient } from "@supabase/ssr";
1
2
  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
+ };
2
36
  const clearAuthState = (req, res) => {
3
37
  req.serverAuthState.clear();
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
- }
38
+ const { cookieName } = createSupabaseServerClient(req, res);
39
+ if (cookieName) {
40
+ res.cookies.unset(cookieName);
13
41
  }
14
42
  res.cookies.unset(AUTH_PROVIDER_HEADER);
15
43
  };
16
44
  export {
17
- clearAuthState
45
+ clearAuthState,
46
+ createSupabaseServerClient
18
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-supabase-middleware",
3
- "version": "5.0.2-rc.5",
3
+ "version": "6.0.0-canary.2616",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -38,16 +38,16 @@
38
38
  "test:watch": "vitest watch"
39
39
  },
40
40
  "dependencies": {
41
- "@cedarjs/auth-supabase-api": "5.0.2-rc.5",
42
- "@cedarjs/web": "5.0.2-rc.5",
41
+ "@cedarjs/auth-supabase-api": "6.0.0-canary.2616",
42
+ "@cedarjs/web": "6.0.0-canary.2616",
43
43
  "@supabase/ssr": "0.12.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@arethetypeswrong/cli": "0.18.4",
47
- "@cedarjs/api": "5.0.2-rc.5",
48
- "@cedarjs/auth": "5.0.2-rc.5",
49
- "@cedarjs/framework-tools": "5.0.2-rc.5",
50
- "@cedarjs/graphql-server": "5.0.2-rc.5",
47
+ "@cedarjs/api": "6.0.0-canary.2616",
48
+ "@cedarjs/auth": "6.0.0-canary.2616",
49
+ "@cedarjs/framework-tools": "6.0.0-canary.2616",
50
+ "@cedarjs/graphql-server": "6.0.0-canary.2616",
51
51
  "@types/aws-lambda": "8.10.162",
52
52
  "concurrently": "9.2.1",
53
53
  "publint": "0.3.21",