@cedarjs/auth-supabase-middleware 5.0.0 → 5.0.1-next.12
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/cjs/util.d.ts +0 -8
- package/dist/cjs/util.d.ts.map +1 -1
- package/dist/cjs/util.js +11 -41
- package/dist/util.d.ts +0 -8
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +10 -39
- package/package.json +1 -1
package/dist/cjs/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").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/cjs/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/cjs/util.js
CHANGED
|
@@ -18,55 +18,25 @@ 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
|
|
22
|
-
createSupabaseServerClient: () => createSupabaseServerClient
|
|
21
|
+
clearAuthState: () => clearAuthState
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(util_exports);
|
|
25
|
-
var import_ssr = require("@supabase/ssr");
|
|
26
24
|
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
25
|
const clearAuthState = (req, res) => {
|
|
61
26
|
req.serverAuthState.clear();
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
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
|
+
}
|
|
65
36
|
}
|
|
66
37
|
res.cookies.unset(import_api.AUTH_PROVIDER_HEADER);
|
|
67
38
|
};
|
|
68
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
40
|
0 && (module.exports = {
|
|
70
|
-
clearAuthState
|
|
71
|
-
createSupabaseServerClient
|
|
41
|
+
clearAuthState
|
|
72
42
|
});
|
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
|
};
|