@payez/next-mvp 4.1.2 → 4.1.3

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.
@@ -54,8 +54,21 @@ async function GET(req) {
54
54
  }
55
55
  const token = baSession;
56
56
  const sessionToken = baSession.session?.token;
57
- const session = sessionToken ? await (0, session_store_1.getSession)(sessionToken) : null;
58
- // CRITICAL: Detect stale cookie state (JWT exists but Redis session missing)
57
+ // Try the canonical session-store first; fall back to the Better-Auth-keyed
58
+ // Redis record (`ba:{appSlug}:{token}`) when the canonical lookup misses.
59
+ // Without the fallback, any consumer that wrote a BA session via the OAuth
60
+ // callback path or dev-login and didn't separately populate the canonical
61
+ // store would land here with a "Stale session" verdict, even though the BA
62
+ // stack just resolved the cookie cleanly. Keeps the two viability impls
63
+ // (this route + `api-handlers/session/viability.ts`) in lockstep.
64
+ let session = sessionToken ? await (0, session_store_1.getSession)(sessionToken) : null;
65
+ if (sessionToken && !session) {
66
+ session = await (0, session_store_1.getBetterAuthSession)(sessionToken);
67
+ if (session) {
68
+ console.log('[VIABILITY] Found session in Better Auth store (fallback)');
69
+ }
70
+ }
71
+ // CRITICAL: Detect stale cookie state (cookie exists but neither store has the session)
59
72
  if (sessionToken && !session) {
60
73
  console.warn('[VIABILITY] Stale cookie detected - session not in Redis');
61
74
  return server_1.NextResponse.json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payez/next-mvp",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,10 @@
16
16
 
17
17
  import { NextRequest, NextResponse } from 'next/server';
18
18
  import { getSession as getBetterAuthSession } from '../../server/auth';
19
- import { getSession as getRedisSession } from '../../lib/session-store';
19
+ import {
20
+ getSession as getRedisSession,
21
+ getBetterAuthSession as getBetterAuthRedisSession,
22
+ } from '../../lib/session-store';
20
23
  import { getIDPClientConfig } from '../../lib/idp-client-config';
21
24
 
22
25
  /**
@@ -55,9 +58,23 @@ export async function GET(req: NextRequest) {
55
58
 
56
59
  const token = baSession as any;
57
60
  const sessionToken = baSession.session?.token;
58
- const session = sessionToken ? await getRedisSession(sessionToken) : null;
59
61
 
60
- // CRITICAL: Detect stale cookie state (JWT exists but Redis session missing)
62
+ // Try the canonical session-store first; fall back to the Better-Auth-keyed
63
+ // Redis record (`ba:{appSlug}:{token}`) when the canonical lookup misses.
64
+ // Without the fallback, any consumer that wrote a BA session via the OAuth
65
+ // callback path or dev-login and didn't separately populate the canonical
66
+ // store would land here with a "Stale session" verdict, even though the BA
67
+ // stack just resolved the cookie cleanly. Keeps the two viability impls
68
+ // (this route + `api-handlers/session/viability.ts`) in lockstep.
69
+ let session = sessionToken ? await getRedisSession(sessionToken) : null;
70
+ if (sessionToken && !session) {
71
+ session = await getBetterAuthRedisSession(sessionToken);
72
+ if (session) {
73
+ console.log('[VIABILITY] Found session in Better Auth store (fallback)');
74
+ }
75
+ }
76
+
77
+ // CRITICAL: Detect stale cookie state (cookie exists but neither store has the session)
61
78
  if (sessionToken && !session) {
62
79
  console.warn('[VIABILITY] Stale cookie detected - session not in Redis');
63
80
  return NextResponse.json({