Skip to content

Commit 1c7e1a5

Browse files
committed
feat(common): use jwt url value for load redirect
1 parent 5f5975e commit 1c7e1a5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pages/api/load.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { NextApiRequest, NextApiResponse } from 'next';
22
import { 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+
411
export 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 });

0 commit comments

Comments
 (0)