add other projects
This commit is contained in:
24
apps/studio.saladeaula.digital/app/routes/auth/logout.ts
Normal file
24
apps/studio.saladeaula.digital/app/routes/auth/logout.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import { createAuth, type User } from '@/lib/auth'
|
||||
import { createSessionStorage } from '@/lib/session'
|
||||
import { redirect } from 'react-router'
|
||||
import type { OAuth2Strategy } from 'remix-auth-oauth2'
|
||||
|
||||
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||
const authenticator = createAuth(context.cloudflare.env)
|
||||
const sessionStorage = createSessionStorage(context.cloudflare.env)
|
||||
const session = await sessionStorage.getSession(request.headers.get('cookie'))
|
||||
const user = session.get('user') as User
|
||||
const strategy = authenticator.get<OAuth2Strategy<User>>('oidc')
|
||||
|
||||
if (user?.accessToken && strategy) {
|
||||
await strategy.revokeToken(user.accessToken)
|
||||
}
|
||||
|
||||
console.log(await sessionStorage.destroySession(session))
|
||||
|
||||
return redirect('/login', {
|
||||
headers: { 'Set-Cookie': await sessionStorage.destroySession(session) }
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user