openvibers/openvibe.tools Commits

GET /auth/me signed out answers 200 { user: null } like Blog, Community and Wiki (a 401 showed in every signed-out visitor's console) (#78)

OP OpenVibers committed 27 days ago · 0f2f69850b · 1 file, +2 −2

Changes

ddiff --git a/apps/gateway/server/auth/routes.js b/apps/gateway/server/auth/routes.js
iindex 7be927b..a90f8a9 100644
---- a/apps/gateway/server/auth/routes.js
++++ b/apps/gateway/server/auth/routes.js
@@@ -459,9 +459,9 @@ function createAuthRoutes(config, auth) {
// ── GET /auth/me ─────────────────────────────────────────
router.get('/me', async (req, res) => {
const token = extractToken(req);
-- if (!token) return res.status(401).json({ error: 'Not authenticated' });
++ if (!token) return res.json({ user: null }); // signed out: 200 with no user (as Blog, Community, Wiki), not a 401 in every signed-out visitor's console
const claims = await auth.verify(token);
-- if (!claims) return res.status(401).json({ error: 'Invalid or expired token' });
++ if (!claims) return res.json({ user: null }); // an expired token is signed out too; the navbar refreshes through /auth/refresh
const { iat, exp, aud, iss, ...user } = claims;
res.json({ user, expires_at: exp ? exp * 1000 : null });
});