Skip to content

Commit e3981f0

Browse files
committed
I think that's the redirect
1 parent 626e1c7 commit e3981f0

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

app/components/Header/AuthModal.client.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ watch(handleInput, newHandleInput => {
5050
handleInput.value = normalized
5151
}
5252
})
53+
54+
watch(user, async newUser => {
55+
if (newUser?.relogin) {
56+
await authRedirect(newUser.did, {
57+
redirectTo: route.fullPath,
58+
})
59+
}
60+
})
5361
</script>
5462

5563
<template>

server/api/auth/session.get.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,17 @@ export default defineEventHandler(async event => {
88
return null
99
}
1010

11+
// A one time redirect to upgrade the previous sessions.
12+
// Can remove in 2 weeks from merge if we'd like
13+
if (serverSession.data.oauthSession && serverSession.data?.public?.did) {
14+
await serverSession.update({
15+
oauthSession: undefined,
16+
})
17+
return {
18+
...result.output,
19+
relogin: true,
20+
}
21+
}
22+
1123
return result.output
1224
})

server/utils/atproto/oauth.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ export function eventHandlerWithOAuthSession<T extends EventHandlerRequest, D>(
157157
return defineEventHandler(async event => {
158158
const { oauthSession, serverSession } = await getOAuthSession(event)
159159

160-
//A one time redirect to upgrade the previous sessions. Can remove in 2 weeks from merge if we'd like
161-
if (serverSession.data.oauthSession && serverSession.data?.public?.did) {
162-
return sendRedirect(event, `/api/auth/atproto?hanlde=${serverSession.data?.public?.did}`)
163-
}
164-
165160
return await handler(event, oauthSession, serverSession)
166161
})
167162
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { object, string, pipe, url, optional } from 'valibot'
1+
import * as v from 'valibot'
22
import type { InferOutput } from 'valibot'
33

4-
export const PublicUserSessionSchema = object({
4+
export const PublicUserSessionSchema = v.object({
55
// Safe to pass to the frontend
6-
did: string(),
7-
handle: string(),
8-
pds: pipe(string(), url()),
9-
avatar: optional(pipe(string(), url())),
6+
did: v.string(),
7+
handle: v.string(),
8+
pds: v.pipe(v.string(), v.url()),
9+
avatar: v.optional(v.pipe(v.string(), v.url())),
10+
relogin: v.optional(v.boolean()),
1011
})
1112

1213
export type PublicUserSession = InferOutput<typeof PublicUserSessionSchema>

shared/types/userSession.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface UserServerSession {
77
handle: string
88
pds: string
99
avatar?: string
10+
relogin?: boolean
1011
}
1112
| undefined
1213
// These values are tied to the users browser session and used by atproto OAuth

0 commit comments

Comments
 (0)