@@ -13,25 +13,13 @@ import {
1313
1414export async function GET ( event ) {
1515 const url = event . url ;
16- // const cookies = event.cookies;
17-
18- // const urlState = url.searchParams.get('state');
1916 const code = url . searchParams . get ( 'code' ) ;
2017
2118 // !urlState || !code
2219 if ( ! code ) {
23- return error ( 418 ) ;
20+ return error ( 400 , { message : 'no oauth code, hmm what happened here' } ) ;
2421 }
2522
26- // const cookieState = cookies.get('oauth_state');
27-
28- // if (!cookieState || cookieState !== urlState) {
29- // const redirectURL = new URL(`${url.protocol}//${url.host}/auth/failed`);
30- // return redirect(302, redirectURL);
31- // }
32-
33- // cookies.delete('oauth_state', { path: '/' });
34-
3523 // Get token
3624 const tokenURL = new URL ( `https://${ env . IDV_DOMAIN } /oauth/token` ) ;
3725
@@ -48,8 +36,7 @@ export async function GET(event) {
4836 } ) ;
4937
5038 if ( ! tokenRes . ok ) {
51- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /auth/failed` ) ;
52- return redirect ( 302 , redirectURL ) ;
39+ return redirect ( 302 , '/auth/failed' ) ;
5340 }
5441
5542 const token = ( await tokenRes . json ( ) ) . access_token ;
@@ -64,8 +51,7 @@ export async function GET(event) {
6451 } ) ;
6552
6653 if ( ! userDataRes . ok ) {
67- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /auth/failed` ) ;
68- return redirect ( 302 , redirectURL ) ;
54+ return redirect ( 302 , '/auth/failed' ) ;
6955 }
7056
7157 const userDataJSON = await userDataRes . json ( ) ;
@@ -99,8 +85,7 @@ export async function GET(event) {
9985 if ( ! slackProfileResJSON . ok ) {
10086 console . error ( 'Failed to fetch user profile' ) ;
10187
102- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /auth/failed` ) ;
103- return redirect ( 302 , redirectURL ) ;
88+ return redirect ( 302 , '/auth/failed' ) ;
10489 }
10590
10691 const slackProfile = slackProfileResJSON [ 'user' ] ;
@@ -128,14 +113,11 @@ export async function GET(event) {
128113 if ( ! channelMembersResJSON . ok ) {
129114 console . error ( 'Failed to fetch channel members' ) ;
130115
131- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /auth/failed` ) ;
132- return redirect ( 302 , redirectURL ) ;
116+ return redirect ( 302 , '/auth/failed' ) ;
133117 }
134118
135119 if ( ! channelMembersResJSON [ 'members' ] . includes ( slack_id ) ) {
136- // redirect to funny url
137- const redirectURL = new URL ( `https://www.youtube.com/watch?v=xvFZjo5PgG0` ) ;
138- return redirect ( 302 , redirectURL ) ;
120+ return redirect ( 302 , '/countdown' ) ;
139121 }
140122 }
141123
@@ -147,7 +129,8 @@ export async function GET(event) {
147129 ) [ 'trust_level' ] ;
148130
149131 if ( ! hackatimeTrust ) {
150- return error ( 418 , {
132+ console . error ( )
133+ return error ( 503 , {
151134 message : 'failed to fetch hackatime trust factor, please try again later'
152135 } ) ;
153136 } else if ( hackatimeTrust === 'red' ) {
@@ -156,8 +139,7 @@ export async function GET(event) {
156139 }
157140
158141 if ( ! ysws_eligible ) {
159- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /auth/ineligible` ) ;
160- return redirect ( 302 , redirectURL ) ;
142+ return redirect ( 302 , '/auth/ineligible' ) ;
161143 }
162144
163145 // Create user if doesn't exist
@@ -218,6 +200,5 @@ export async function GET(event) {
218200 new Date ( Date . now ( ) + DAY_IN_MS * SESSION_EXPIRY_DAYS )
219201 ) ;
220202
221- const redirectURL = new URL ( `${ url . protocol } //${ url . host } /dashboard` ) ;
222- return redirect ( 302 , redirectURL ) ;
203+ return redirect ( 302 , '/dashboard' ) ;
223204}
0 commit comments