Skip to content

Commit 98df155

Browse files
committed
draft: check client metadata
1 parent 62e4056 commit 98df155

1 file changed

Lines changed: 1 addition & 73 deletions

File tree

server/api/auth/atproto.get.ts

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -54,77 +54,5 @@ export default defineEventHandler(async event => {
5454

5555
const query = getQuery(event)
5656
const clientMetadata = getOauthClientMetadata()
57-
const session = await useServerSession(event)
58-
const { stateStore, sessionStore } = useOAuthStorage(session)
59-
60-
const atclient = new NodeOAuthClient({
61-
stateStore,
62-
sessionStore,
63-
clientMetadata,
64-
requestLock: getOAuthLock(),
65-
handleResolver,
66-
})
67-
68-
if (!query.code) {
69-
try {
70-
const handle = query.handle?.toString()
71-
const create = query.create?.toString()
72-
73-
if (!handle) {
74-
throw createError({
75-
statusCode: 401,
76-
message: 'Handle not provided in query',
77-
})
78-
}
79-
80-
const redirectUrl = await atclient.authorize(handle, {
81-
scope,
82-
prompt: create ? 'create' : undefined,
83-
})
84-
return redirectUrl
85-
} catch (error) {
86-
const message = error instanceof Error ? error.message : 'Authentication failed.'
87-
88-
return handleApiError(error, {
89-
statusCode: 401,
90-
message: `${message}. Please login and try again.`,
91-
})
92-
}
93-
}
94-
95-
const { session: authSession } = await atclient.callback(
96-
new URLSearchParams(query as Record<string, string>),
97-
)
98-
const agent = new Agent(authSession)
99-
event.context.agent = agent
100-
101-
const response = await fetch(
102-
`https://${SLINGSHOT_HOST}/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${agent.did}`,
103-
{ headers: { 'User-Agent': 'npmx' } },
104-
)
105-
if (response.ok) {
106-
const miniDoc: PublicUserSession = await response.json()
107-
108-
let avatar: string | undefined = await getAvatar(authSession.did, miniDoc.pds)
109-
110-
await session.update({
111-
public: {
112-
...miniDoc,
113-
avatar,
114-
},
115-
})
116-
} else {
117-
//If slingshot fails we still want to set some key info we need.
118-
const pdsBase = (await authSession.getTokenInfo()).aud
119-
let avatar: string | undefined = await getAvatar(authSession.did, pdsBase)
120-
await session.update({
121-
public: {
122-
did: authSession.did,
123-
handle: 'Not available',
124-
pds: pdsBase,
125-
avatar,
126-
},
127-
})
128-
}
129-
return sendRedirect(event, '/')
57+
return clientMetadata
13058
})

0 commit comments

Comments
 (0)