File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 11import { NextApiRequest , NextApiResponse } from 'next' ;
22import { encodePayload , getBCVerify , setSession } from '../../lib/auth' ;
33
4+ const buildRedirectUrl = ( url : string , encodedContext : string ) => {
5+ const [ path , query = '' ] = url . split ( '?' ) ;
6+ const queryParams = new URLSearchParams ( `context=${ encodedContext } &${ query } ` ) ;
7+
8+ return `${ path } ?${ queryParams } ` ;
9+ }
10+
411export default async function load ( req : NextApiRequest , res : NextApiResponse ) {
512 try {
613 // Verify when app loaded (launch)
714 const session = await getBCVerify ( req . query ) ;
815 const encodedContext = encodePayload ( session ) ; // Signed JWT to validate/ prevent tampering
916
1017 await setSession ( session ) ;
11- res . redirect ( 302 , `/?context= ${ encodedContext } ` ) ;
18+ res . redirect ( 302 , buildRedirectUrl ( session . url , encodedContext ) ) ;
1219 } catch ( error ) {
1320 const { message, response } = error ;
1421 res . status ( response ?. status || 500 ) . json ( { message } ) ;
You can’t perform that action at this time.
0 commit comments