11import type { OAuthSession } from '@atproto/oauth-client-node'
2- import { NodeOAuthClient , OAuthCallbackError } from '@atproto/oauth-client-node'
2+ import { OAuthCallbackError } from '@atproto/oauth-client-node'
33import { createError , getQuery , sendRedirect , setCookie , getCookie , deleteCookie } from 'h3'
44import type { H3Event } from 'h3'
5- import { getOAuthLock } from '#server/utils/atproto/lock'
6- import { useOAuthStorage } from '#server/utils/atproto/storage'
75import { SLINGSHOT_HOST } from '#shared/utils/constants'
86import { useServerSession } from '#server/utils/server-session'
9- import { handleResolver } from '#server/utils/atproto/oauth'
107import { handleApiError } from '#server/utils/error-handler'
118import type { DidString } from '@atproto/lex'
129import { Client } from '@atproto/lex'
1310import * as com from '#shared/types/lexicons/com'
1411import * as app from '#shared/types/lexicons/app'
1512import { isAtIdentifierString } from '@atproto/lex'
16- import { scope , getOauthClientMetadata } from '#server/utils/atproto/oauth'
13+ import { scope } from '#server/utils/atproto/oauth'
1714import { UNSET_NUXT_SESSION_PASSWORD } from '#shared/utils/constants'
1815// @ts -expect-error virtual file from oauth module
1916import { clientUri } from '#oauth/config'
@@ -28,17 +25,7 @@ export default defineEventHandler(async event => {
2825 }
2926
3027 const query = getQuery ( event )
31- const clientMetadata = getOauthClientMetadata ( )
3228 const session = await useServerSession ( event )
33- const { stateStore, sessionStore } = useOAuthStorage ( session )
34-
35- const atclient = new NodeOAuthClient ( {
36- stateStore,
37- sessionStore,
38- clientMetadata,
39- requestLock : getOAuthLock ( ) ,
40- handleResolver,
41- } )
4229
4330 if ( query . handle ) {
4431 // Initiate auth flow
@@ -66,10 +53,13 @@ export default defineEventHandler(async event => {
6653 }
6754
6855 try {
69- const redirectUrl = await atclient . authorize ( query . handle , {
56+ const redirectUrl = await event . context . oauthClient . authorize ( query . handle , {
7057 scope,
7158 prompt : query . create ? 'create' : undefined ,
72- ui_locales : query . locale ?. toString ( ) ,
59+ // TODO: I do not beleive this is working as expected on
60+ // a unsupported locale on the PDS. Gives Invalid at body.ui_locales
61+ // Commenting out for now
62+ // ui_locales: query.locale?.toString(),
7363 state : encodeOAuthState ( event , { redirectPath } ) ,
7464 } )
7565
@@ -87,7 +77,7 @@ export default defineEventHandler(async event => {
8777 // Handle callback
8878 try {
8979 const params = new URLSearchParams ( query as Record < string , string > )
90- const result = await atclient . callback ( params )
80+ const result = await event . context . oauthClient . callback ( params )
9181 try {
9282 const state = decodeOAuthState ( event , result . state )
9383 const profile = await getMiniProfile ( result . session )
0 commit comments