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 1
1
import { NextApiRequest , NextApiResponse } from 'next' ;
2
2
import { encodePayload , getBCVerify , setSession } from '../../lib/auth' ;
3
3
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
+
4
11
export default async function load ( req : NextApiRequest , res : NextApiResponse ) {
5
12
try {
6
13
// Verify when app loaded (launch)
7
14
const session = await getBCVerify ( req . query ) ;
8
15
const encodedContext = encodePayload ( session ) ; // Signed JWT to validate/ prevent tampering
9
16
10
17
await setSession ( session ) ;
11
- res . redirect ( 302 , `/?context= ${ encodedContext } ` ) ;
18
+ res . redirect ( 302 , buildRedirectUrl ( session . url , encodedContext ) ) ;
12
19
} catch ( error ) {
13
20
const { message, response } = error ;
14
21
res . status ( response ?. status || 500 ) . json ( { message } ) ;
You can’t perform that action at this time.
0 commit comments