File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,21 +31,30 @@ export default defineEventHandler(async event => {
3131 } )
3232
3333 if ( ! query . code ) {
34- const handle = query . handle ?. toString ( )
35- const create = query . create ?. toString ( )
34+ try {
35+ const handle = query . handle ?. toString ( )
36+ const create = query . create ?. toString ( )
3637
37- if ( ! handle ) {
38- throw createError ( {
39- status : 400 ,
40- message : 'Handle not provided in query' ,
38+ if ( ! handle ) {
39+ throw createError ( {
40+ statusCode : 401 ,
41+ message : 'Handle not provided in query' ,
42+ } )
43+ }
44+
45+ const redirectUrl = await atclient . authorize ( handle , {
46+ scope,
47+ prompt : create ? 'create' : undefined ,
4148 } )
42- }
49+ return sendRedirect ( event , redirectUrl . toString ( ) )
50+ } catch ( error ) {
51+ const message = error instanceof Error ? error . message : 'Authentication failed.'
4352
44- const redirectUrl = await atclient . authorize ( handle , {
45- scope ,
46- prompt : create ? 'create' : undefined ,
47- } )
48- return sendRedirect ( event , redirectUrl . toString ( ) )
53+ return handleApiError ( error , {
54+ statusCode : 401 ,
55+ message : ` ${ message } . Please login and try again.` ,
56+ } )
57+ }
4958 }
5059
5160 const { session : authSession } = await atclient . callback (
You can’t perform that action at this time.
0 commit comments