A minimal starter for ATProto logins in Astro
at main 734 B view raw
1import type { APIRoute } from 'astro' 2import { getOAuthClient } from '../../lib/context' 3import { getSession } from '../../lib/session' 4 5export const POST: APIRoute = async (context) => { 6 try { 7 const oauthClient = getOAuthClient(context.cookies) 8 const session = getSession(context.cookies) 9 10 if (session.did) { 11 try { 12 const oauthSession = await oauthClient.restore(session.did) 13 if (oauthSession) await oauthSession.signOut() 14 } catch (err) { 15 console.warn('Failed to revoke credentials:', err) 16 } 17 } 18 19 session.destroy() 20 21 return context.redirect('/') 22 } catch (err) { 23 console.error('Logout failed:', err) 24 return new Response('Logout failed', { status: 500 }) 25 } 26}