@jskit-ai/auth-provider-supabase-core 0.2.13 → 0.2.14

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - 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.
5
6
  - `confirmRegistration` answers `AUTH_OPERATION_UNSUPPORTED`: Supabase confirms an email through its own link.
6
7
 
7
8
  ## 0.2.0 - 2026-10-29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-supabase-core",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
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.11",
64
- "@jskit-ai/kernel": "0.2.11"
63
+ "@jskit-ai/auth-core": "0.2.12",
64
+ "@jskit-ai/kernel": "0.2.12"
65
65
  }
66
66
  }
@@ -2,6 +2,6 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/auth-provider-supabase-core": "0.2.13"
5
+ "@jskit-ai/auth-provider-supabase-core": "0.2.14"
6
6
  }
7
7
  }
@@ -85,15 +85,19 @@ function createSupabaseProfileMirror({ config, profiles }) {
85
85
 
86
86
  /**
87
87
  * With syncProfile: false the caller asks only who is signed in, so the
88
- * existing profile is read instead of synchronized.
88
+ * existing profile is read instead of synchronized. An ordinary request
89
+ * (`onlyWhenChanged`) synchronizes only a missing profile or one that no longer
90
+ * matches the token's identity; a sign-in or a session refresh synchronizes in full.
89
91
  */
90
- async function syncProfileMirror(nextProfile, { syncProfile = true } = {}) {
92
+ async function syncProfileMirror(nextProfile, { syncProfile = true, onlyWhenChanged = false } = {}) {
91
93
  if (!syncProfile) {
92
94
  return findProfileByIdentity(nextProfile);
93
95
  }
94
96
  try {
95
97
  const normalized = buildNormalizedIdentityProfile(nextProfile);
96
- const synchronizedProfile = await projector.syncIdentityProfile(normalized);
98
+ const synchronizedProfile = await (onlyWhenChanged
99
+ ? projector.syncIdentityProfile(normalized, { onlyWhenChanged })
100
+ : projector.syncIdentityProfile(normalized));
97
101
  return requireSynchronizedProfile(synchronizedProfile);
98
102
  } catch (error) {
99
103
  if (String(error?.code || "") === USER_PROFILE_EMAIL_CONFLICT_CODE) {
@@ -169,28 +173,22 @@ function createSupabaseProfileMirror({ config, profiles }) {
169
173
  throw new AppError(401, "Token is missing subject claim.", { code: "auth.supabase.token.subjectMissing" });
170
174
  }
171
175
 
172
- const existing = await findProfileByIdentity({
173
- authProvider: SUPABASE_PROVIDER_ID,
174
- authProviderUserSid: supabaseUserId
175
- });
176
- if (!syncProfile) {
177
- return existing;
178
- }
176
+ const identity = { authProvider: SUPABASE_PROVIDER_ID, authProviderUserSid: supabaseUserId };
179
177
  const emailFromToken = normalizeEmail(claims?.email || "");
180
-
181
- if (!emailFromToken) {
182
- if (existing) {
178
+ if (!syncProfile || !emailFromToken) {
179
+ const existing = await findProfileByIdentity(identity);
180
+ if (!syncProfile || existing) {
183
181
  return existing;
184
182
  }
185
183
  throw new AppError(401, "Token is missing email claim.", { code: "auth.supabase.token.emailMissing" });
186
184
  }
187
185
 
186
+ // An ordinary request: the token's identity is synchronized only when the profile is missing or differs.
188
187
  return syncProfileMirror({
189
- authProvider: SUPABASE_PROVIDER_ID,
190
- authProviderUserSid: supabaseUserId,
188
+ ...identity,
191
189
  email: emailFromToken,
192
190
  displayName: resolveDisplayName(claims, emailFromToken)
193
- });
191
+ }, { onlyWhenChanged: true });
194
192
  }
195
193
 
196
194
  return Object.freeze({
@@ -349,7 +349,7 @@ function createSupabaseSessions({ config, clients, profileMirror, profiles }) {
349
349
  }
350
350
 
351
351
  if (verification.status === "invalid") {
352
- const supabaseVerification = await verifyAccessTokenViaSupabase(accessToken, { syncProfile });
352
+ const supabaseVerification = await verifyAccessTokenViaSupabase(accessToken, { syncProfile, onlyWhenChanged: true });
353
353
  if (supabaseVerification.status === "valid") {
354
354
  return signedIn(supabaseVerification.profile);
355
355
  }