auth: add GET /api/auth/logout?redirect= for browser-based logout links
Mirrors the refresh-session pattern — clears cookies, invalidates refresh token, and redirects to the given URL (falls back to /login.html). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
61f15e1325
commit
7ed9b9d7a2
|
|
@ -137,6 +137,16 @@ router.post( '/logout', ( req, res ) =>
|
|||
res.json( { ok: true } );
|
||||
} );
|
||||
|
||||
// GET /api/auth/logout?redirect=... — browser clients (link/redirect-based logout)
|
||||
router.get( '/logout', ( req, res ) =>
|
||||
{
|
||||
const redirectTo = req.query.redirect as string | undefined;
|
||||
const token = req.cookies?.refreshToken as string | undefined;
|
||||
if ( token ) refreshTokens.delete( token );
|
||||
clearAuthCookies( res );
|
||||
res.redirect( redirectTo ?? '/login.html' );
|
||||
} );
|
||||
|
||||
// POST /api/auth/refresh — non-browser clients (token in body)
|
||||
router.post( '/refresh', ( req, res ) =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue