Skip to content

Commit

Permalink
chore: fix callback error
Browse files Browse the repository at this point in the history
  • Loading branch information
peterphanouvong committed Aug 27, 2024
1 parent b400744 commit 384c2a2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/handlers/callback.js → src/handlers/callback.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {config} from '../config/index';
import RouterClient from '../routerClients/RouterClient';

/**
*
* @param {RouterClient} routerClient
*/
export const callback = async (routerClient) => {
export const callback = async (routerClient: RouterClient) => {
const postLoginRedirectURLFromMemory =
await routerClient.sessionManager.getSessionItem('post_login_redirect_url');

if (postLoginRedirectURLFromMemory) {
routerClient.sessionManager.removeSessionItem('post_login_redirect_url');
await routerClient.sessionManager.removeSessionItem(
'post_login_redirect_url'
);
}

const postLoginRedirectURL = postLoginRedirectURLFromMemory
Expand All @@ -25,6 +23,18 @@ export const callback = async (routerClient) => {
if (config.isDebugMode) {
console.error('callback', error);
}

if (error.message.includes('Expected: State not found')) {
return routerClient.json(
{
error:
`Error: State not found.\nTo resolve this error please visit our docs https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/#state-not-found-error` +
error.message
},
{status: 500}
);
}

return routerClient.json({error: error.message}, {status: 500});
}
if (postLoginRedirectURL) {
Expand Down

0 comments on commit 384c2a2

Please sign in to comment.