Skip to content

Commit 1b5fe44

Browse files
committed
Merge branch 'development' into staging
2 parents 25a3d05 + 8d02dc2 commit 1b5fe44

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/client/app/api/auth/token/route.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ export async function GET() {
3030
return NextResponse.json({ accessToken: token })
3131
} catch (error) {
3232
console.error("Error in /api/auth/token:", error)
33+
// If the error is specifically because of a missing session,
34+
// return a 401 Unauthorized status, which is more appropriate
35+
// and allows the client to handle it by redirecting to login.
36+
if (error.code === "missing_session") {
37+
return NextResponse.json(
38+
{ message: error.message },
39+
{ status: 401 }
40+
)
41+
}
3342
return NextResponse.json(
3443
{ message: "Internal Server Error", error: error.message },
3544
{ status: 500 }

src/client/app/api/user/data/route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export const GET = withAuth(async function GET(request, { authHeader }) {
1515
cache: "no-store" // Prevent Next.js from caching this server-side fetch
1616
})
1717

18-
const data = await response.json()
1918
if (!response.ok) {
19+
const data = await response.json()
2020
throw new Error(
2121
data.message || "Failed to fetch user data from backend"
2222
)
2323
}
24-
24+
const data = await response.json()
2525
return NextResponse.json(data)
2626
} catch (error) {
2727
console.error("API Error in /user/data:", error)

0 commit comments

Comments
 (0)