cloudflare-next-intl 0.6.9 → 0.6.10
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.
|
@@ -33,13 +33,14 @@ function clearRefreshTokenCookie(refreshTokenCookieName) {
|
|
|
33
33
|
function writeEmailVerifiedHintCookie(emailVerifiedHintCookieName, emailVerified, maxAge) {
|
|
34
34
|
setCookie({ name: emailVerifiedHintCookieName, value: String(emailVerified), maxAge });
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
setCookie({ name: emailVerifiedHintCookieName, value: '', maxAge: 0 });
|
|
38
|
-
}
|
|
39
|
-
async function clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName) {
|
|
36
|
+
async function clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName, refreshTokenMaxAge) {
|
|
40
37
|
clearSessionCookie(sessionCookieName);
|
|
41
38
|
clearRefreshTokenCookie(refreshTokenCookieName);
|
|
42
|
-
|
|
39
|
+
// Signed-out is not "unknown" — it's a confirmed non-verified state, so
|
|
40
|
+
// write 'false' explicitly rather than clearing (an absent hint means
|
|
41
|
+
// "no signal yet", which forces the middleware to refresh unnecessarily
|
|
42
|
+
// if a stale session cookie somehow still lingers).
|
|
43
|
+
writeEmailVerifiedHintCookie(emailVerifiedHintCookieName, false, refreshTokenMaxAge);
|
|
43
44
|
try {
|
|
44
45
|
await clearSessionAction();
|
|
45
46
|
}
|
|
@@ -130,7 +131,7 @@ export default function AuthUserProvider({ initialUser = null, children }) {
|
|
|
130
131
|
await writeSession(user, sessionCookieName, maxAge, refreshTokenCookieName, refreshTokenMaxAge, emailVerifiedHintCookieName);
|
|
131
132
|
}
|
|
132
133
|
else {
|
|
133
|
-
await clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName);
|
|
134
|
+
await clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName, refreshTokenMaxAge);
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
catch (e) {
|
|
@@ -195,7 +196,7 @@ export default function AuthUserProvider({ initialUser = null, children }) {
|
|
|
195
196
|
await signOut(auth);
|
|
196
197
|
}
|
|
197
198
|
finally {
|
|
198
|
-
await clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName);
|
|
199
|
+
await clearSession(sessionCookieName, refreshTokenCookieName, emailVerifiedHintCookieName, refreshTokenMaxAge);
|
|
199
200
|
router.push(fa.redirectAuthPath);
|
|
200
201
|
}
|
|
201
202
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -228,18 +228,18 @@ export default async function updateSession(request, baseResponse, locale) {
|
|
|
228
228
|
// (up to ~1hr later). AuthUserProvider (client) mirrors the live SDK
|
|
229
229
|
// state into `emailVerifiedHintCookieName` on every auth-state change,
|
|
230
230
|
// so it reflects verification status sooner than the session JWT does.
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
// claim
|
|
236
|
-
//
|
|
237
|
-
//
|
|
231
|
+
// Force one refresh to confirm before redirecting whenever that hint
|
|
232
|
+
// can't yet vouch for this claim: it disagrees outright, or it's absent
|
|
233
|
+
// (e.g. first request before the client has run at all, or a hint
|
|
234
|
+
// that expired/was never set) — either way there's no positive signal
|
|
235
|
+
// the claim is still accurate. Only when the hint AGREES with the claim
|
|
236
|
+
// is a refresh skipped, so a genuinely unverified user with an
|
|
237
|
+
// established, agreeing hint doesn't pay a refresh on every request.
|
|
238
238
|
let unverifiedEmail = false;
|
|
239
239
|
if (fa.verifyEmailPath && !isVerifyEmailPage && hasSession && decodeJwtPayload(token)?.email_verified === false) {
|
|
240
240
|
const hint = request.cookies.get(emailVerifiedHintCookieName)?.value;
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
241
|
+
const hintConfirms = hint === 'false';
|
|
242
|
+
if (!hintConfirms && !refreshedToken) {
|
|
243
243
|
const refreshToken = request.cookies.get(refreshTokenCookieName)?.value;
|
|
244
244
|
if (refreshToken) {
|
|
245
245
|
const result = await refreshIdToken(fa.apiKey, refreshToken);
|
|
@@ -264,7 +264,7 @@ export default async function updateSession(request, baseResponse, locale) {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
else {
|
|
267
|
-
// Hint
|
|
267
|
+
// Hint confirms unverified — no reason to refresh, trust the claim.
|
|
268
268
|
unverifiedEmail = true;
|
|
269
269
|
}
|
|
270
270
|
}
|