File tree Expand file tree Collapse file tree 2 files changed +44
-33
lines changed Expand file tree Collapse file tree 2 files changed +44
-33
lines changed Original file line number Diff line number Diff line change 11export default defineEventHandler ( async ( event ) => {
2- const config = useRuntimeConfig ( )
3- const body = await readBody ( event )
2+ try {
3+ const config = useRuntimeConfig ( )
4+ const body = await readBody ( event )
45
5- const url = `${ config . public . COMMUNITY_API_URL } /auth/`
6- const loginOptions = {
7- method : "POST" ,
8- body : body ,
9- headers : {
10- "Accept" : "*/*" ,
11- "Content-Type" : "application/json"
6+ const url = `${ config . public . COMMUNITY_API_URL } /auth/`
7+ const loginOptions = {
8+ method : "POST" ,
9+ body : body ,
10+ headers : {
11+ "Accept" : "*/*" ,
12+ "Content-Type" : "application/json"
13+ }
1214 }
13- }
1415
15- const loginResponse = await $fetch . raw ( url + 'login' , loginOptions ) ;
16+ const loginResponse = await $fetch . raw ( url + 'login' , loginOptions ) ;
1617
17- const authResponse = await $fetch . raw ( url , {
18- method : 'GET' ,
19- headers : {
20- "Accept" : "*/*" ,
21- "Cookie" : loginResponse . headers . get ( 'set-cookie' )
22- }
23- } )
24- appendHeader ( event , 'Set-Cookie' , loginResponse . headers . get ( 'set-cookie' ) ) // assuming we only set one cookie
25- return authResponse . _data
18+ const authResponse = await $fetch . raw ( url , {
19+ method : 'GET' ,
20+ headers : {
21+ "Accept" : "*/*" ,
22+ "Cookie" : loginResponse . headers . get ( 'set-cookie' )
23+ }
24+ } )
25+ appendHeader ( event , 'Set-Cookie' , loginResponse . headers . get ( 'set-cookie' ) ) // assuming we only set one cookie
26+ return authResponse . _data
27+
28+ } catch ( error ) {
29+ console . log ( error ) ;
30+ return false ;
31+ }
2632} ) ;
Original file line number Diff line number Diff line change 11export default defineEventHandler ( async ( event ) => {
2- const query = getQuery ( event )
3- const config = useRuntimeConfig ( )
4- const sessionCookie = getCookie ( event , `${ config . public . SESSION_COOKIE_NAME } ` ) ;
2+ try {
3+ const query = getQuery ( event )
4+ const config = useRuntimeConfig ( )
5+ const sessionCookie = getCookie ( event , `${ config . public . SESSION_COOKIE_NAME } ` ) ;
56
6- const url = `${ config . public . COMMUNITY_API_URL } /member/${ query . id } `
7- const options = {
8- method : "GET" ,
9- headers : {
10- "Accept" : "*/*" ,
11- "Content-Type" : "application/json" ,
12- "Cookie" : `${ config . public . SESSION_COOKIE_NAME } =` + sessionCookie ,
7+ const url = `${ config . public . COMMUNITY_API_URL } /member/${ query . id } `
8+ const options = {
9+ method : "GET" ,
10+ headers : {
11+ "Accept" : "*/*" ,
12+ "Content-Type" : "application/json" ,
13+ "Cookie" : `${ config . public . SESSION_COOKIE_NAME } =` + sessionCookie ,
14+ }
1315 }
14- }
1516
16- const response = await $fetch . raw ( url , options ) ;
17- return response . _data
17+ const response = await $fetch . raw ( url , options ) ;
18+ return response . _data
19+ } catch ( error ) {
20+ console . log ( error ) ;
21+ return false ;
22+ }
1823} ) ;
You can’t perform that action at this time.
0 commit comments