@jskit-ai/auth-provider-supabase-core 0.2.32 → 0.2.33
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/CHANGELOG.md +1 -0
- package/package.json +3 -3
- package/patterns/supabase-auth/example/package.json +1 -1
- package/src/server/lib/authCookies.js +5 -5
- package/src/server/lib/config.js +2 -2
- package/src/server/lib/sessions.js +10 -10
- package/test/auth.provider.supabase.test.js +2 -2
- package/test/devAuthBootstrap.test.js +1 -1
- package/test/providerRuntime.test.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Breaking:** staging and production (`APP_ENV`), not `NODE_ENV=production`, use secure `__Host-` session cookies and refuse development shortcuts; the config's `isProduction` is now `isDeployed`.
|
|
5
6
|
- The second-factor operations (`getSecondFactorStatus`, `startSecondFactorSetup`, `confirmSecondFactorSetup`, `verifySecondFactor`, `replaceSecondFactorRecoveryCodes`, `removeSecondFactor`, `listSecondFactors`, `resetSecondFactor`) answer `AUTH_OPERATION_UNSUPPORTED`, and `features.secondFactor` is false.
|
|
6
7
|
- Reading the signed-in user for the security screen and account changes asks Supabase for a valid access token's user once instead of twice; it asks again only for the new token a session refresh issued.
|
|
7
8
|
- A request with a valid access token synchronizes the app profile only when it is missing or no longer matches the token's email and display name (`onlyWhenChanged`), after one read instead of two plus a transaction; sign-in, account changes and a session refresh synchronize in full. Visible difference: a personal workspace, owner membership or settings row deleted while someone is signed in comes back at their next session refresh or sign-in instead of their next request.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-provider-supabase-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@jskit-ai/auth-core": "0.2.
|
|
64
|
-
"@jskit-ai/kernel": "0.2.
|
|
63
|
+
"@jskit-ai/auth-core": "0.2.30",
|
|
64
|
+
"@jskit-ai/kernel": "0.2.27"
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -6,11 +6,11 @@ function safeRequestCookies(request) {
|
|
|
6
6
|
return {};
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function cookieOptions(
|
|
9
|
+
function cookieOptions(isDeployed, maxAge) {
|
|
10
10
|
const options = {
|
|
11
11
|
httpOnly: true,
|
|
12
12
|
sameSite: "lax",
|
|
13
|
-
secure:
|
|
13
|
+
secure: isDeployed,
|
|
14
14
|
path: "/"
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -21,11 +21,11 @@ function cookieOptions(isProduction, maxAge) {
|
|
|
21
21
|
return options;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function cookieClearOptions(
|
|
24
|
+
function cookieClearOptions(isDeployed) {
|
|
25
25
|
return [
|
|
26
|
-
cookieOptions(
|
|
26
|
+
cookieOptions(isDeployed, 0),
|
|
27
27
|
{
|
|
28
|
-
...cookieOptions(
|
|
28
|
+
...cookieOptions(isDeployed, 0),
|
|
29
29
|
path: "/api"
|
|
30
30
|
}
|
|
31
31
|
];
|
package/src/server/lib/config.js
CHANGED
|
@@ -49,7 +49,7 @@ function assertSelectedProvider(env) {
|
|
|
49
49
|
/**
|
|
50
50
|
* Supabase auth's settings, read once from the app's config and Env: the
|
|
51
51
|
* project, where profiles live, the app's addresses, its OAuth providers and
|
|
52
|
-
* dev auth.
|
|
52
|
+
* dev auth. Whether it is deployed is worked out once, by auth-core's dev auth policy.
|
|
53
53
|
* @param {object} sources
|
|
54
54
|
* @param {import("@jskit-ai/kernel/server/types").RuntimeConfig} sources.config
|
|
55
55
|
* @param {import("@jskit-ai/kernel/server/types").RuntimeEnv} sources.env
|
|
@@ -74,7 +74,7 @@ function resolveSupabaseConfig({ config, env }) {
|
|
|
74
74
|
supabasePublishableKey,
|
|
75
75
|
configured: Boolean(supabaseUrl && supabasePublishableKey),
|
|
76
76
|
jwtAudience,
|
|
77
|
-
|
|
77
|
+
isDeployed: devAuth.isDeployed,
|
|
78
78
|
appPublicUrl,
|
|
79
79
|
allowedReturnToOrigins: resolveAllowedOriginsFromSurfaceDefinitions(config.surfaceDefinitions || {}, {
|
|
80
80
|
seedOrigins: [appPublicUrl]
|
|
@@ -22,12 +22,12 @@ const PERSISTENT_SESSION_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 400;
|
|
|
22
22
|
* @param {import("../types.js").SupabaseProfiles} dependencies.profiles
|
|
23
23
|
*/
|
|
24
24
|
function createSupabaseSessions({ config, clients, profileMirror, profiles }) {
|
|
25
|
-
const {
|
|
26
|
-
//
|
|
27
|
-
const ACCESS_TOKEN_COOKIE = hostOnlyCookieName(ACCESS_TOKEN_COOKIE_NAME,
|
|
28
|
-
const REFRESH_TOKEN_COOKIE = hostOnlyCookieName(REFRESH_TOKEN_COOKIE_NAME,
|
|
29
|
-
const RECOVERY_ACCESS_TOKEN_COOKIE = hostOnlyCookieName(RECOVERY_ACCESS_TOKEN_COOKIE_NAME,
|
|
30
|
-
const RECOVERY_REFRESH_TOKEN_COOKIE = hostOnlyCookieName(RECOVERY_REFRESH_TOKEN_COOKIE_NAME,
|
|
25
|
+
const { isDeployed, jwtAudience, supabaseUrl } = config;
|
|
26
|
+
// Staging and production cookies are Secure, so they are also host-only __Host- cookies.
|
|
27
|
+
const ACCESS_TOKEN_COOKIE = hostOnlyCookieName(ACCESS_TOKEN_COOKIE_NAME, isDeployed);
|
|
28
|
+
const REFRESH_TOKEN_COOKIE = hostOnlyCookieName(REFRESH_TOKEN_COOKIE_NAME, isDeployed);
|
|
29
|
+
const RECOVERY_ACCESS_TOKEN_COOKIE = hostOnlyCookieName(RECOVERY_ACCESS_TOKEN_COOKIE_NAME, isDeployed);
|
|
30
|
+
const RECOVERY_REFRESH_TOKEN_COOKIE = hostOnlyCookieName(RECOVERY_REFRESH_TOKEN_COOKIE_NAME, isDeployed);
|
|
31
31
|
const issuerUrl = supabaseUrl ? new URL("/auth/v1", supabaseUrl).toString().replace(/\/$/, "") : "";
|
|
32
32
|
const jwksUrl = issuerUrl ? `${issuerUrl}/.well-known/jwks.json` : "";
|
|
33
33
|
|
|
@@ -255,14 +255,14 @@ function createSupabaseSessions({ config, clients, profileMirror, profiles }) {
|
|
|
255
255
|
? Math.floor(sessionAccessMaxAge)
|
|
256
256
|
: Math.max(Math.floor(sessionAccessMaxAge), PERSISTENT_SESSION_COOKIE_MAX_AGE_SECONDS);
|
|
257
257
|
|
|
258
|
-
reply.setCookie(accessCookieName, accessToken, cookieOptions(
|
|
259
|
-
reply.setCookie(refreshCookieName, refreshToken, cookieOptions(
|
|
258
|
+
reply.setCookie(accessCookieName, accessToken, cookieOptions(isDeployed, cookieMaxAge));
|
|
259
|
+
reply.setCookie(refreshCookieName, refreshToken, cookieOptions(isDeployed, cookieMaxAge));
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
function clearSessionCookies(reply) {
|
|
263
|
-
for (const clearOptions of cookieClearOptions(
|
|
263
|
+
for (const clearOptions of cookieClearOptions(isDeployed)) {
|
|
264
264
|
// A __Host- cookie only exists at Path=/.
|
|
265
|
-
if (clearOptions.path === "/" || !
|
|
265
|
+
if (clearOptions.path === "/" || !isDeployed) {
|
|
266
266
|
reply.clearCookie(ACCESS_TOKEN_COOKIE, clearOptions);
|
|
267
267
|
reply.clearCookie(REFRESH_TOKEN_COOKIE, clearOptions);
|
|
268
268
|
reply.clearCookie(RECOVERY_ACCESS_TOKEN_COOKIE, clearOptions);
|
|
@@ -17,7 +17,7 @@ test("auth.provider.supabase exports required symbols", () => {
|
|
|
17
17
|
function supabaseConfig(env = {}) {
|
|
18
18
|
return resolveSupabaseConfig({
|
|
19
19
|
config: {},
|
|
20
|
-
env: { APP_PUBLIC_URL: "http://localhost:5173",
|
|
20
|
+
env: { APP_PUBLIC_URL: "http://localhost:5173", APP_ENV: "development", ...env }
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -74,7 +74,7 @@ test("clearSessionCookies clears root and API path session cookie variants", ()
|
|
|
74
74
|
|
|
75
75
|
test("clearSessionCookies preserves secure cookie clearing in production", () => {
|
|
76
76
|
const authService = createServiceFixture({
|
|
77
|
-
env: { NODE_ENV: "production" }
|
|
77
|
+
env: { APP_ENV: "production", NODE_ENV: "production" }
|
|
78
78
|
});
|
|
79
79
|
const clearCalls = [];
|
|
80
80
|
const reply = {
|
|
@@ -85,7 +85,7 @@ function createServiceFixture({ userProfilesRepository = createUserProfilesRepos
|
|
|
85
85
|
config: { auth: { profileMode: "users" } },
|
|
86
86
|
env: {
|
|
87
87
|
APP_PUBLIC_URL: "http://localhost:5173",
|
|
88
|
-
|
|
88
|
+
APP_ENV: "development",
|
|
89
89
|
AUTH_JWT_AUDIENCE: "authenticated",
|
|
90
90
|
AUTH_DEV_BYPASS_ENABLED: true,
|
|
91
91
|
AUTH_DEV_BYPASS_SECRET: DEV_AUTH_SECRET
|