Skip to content

Commit

Permalink
Merge pull request #192 from kinde-oss/fix/postlogouturl
Browse files Browse the repository at this point in the history
fix: Post logout redirect URL
  • Loading branch information
peterphanouvong authored Jul 22, 2024
2 parents 2db7533 + 7b4d36d commit 9509ac4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/handlers/logout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { config } from '../config/index';
import RouterClient from '../routerClients/RouterClient';

/**
Expand All @@ -6,21 +7,15 @@ import RouterClient from '../routerClients/RouterClient';
*/
export const logout = async (routerClient) => {
const authUrl = await routerClient.kindeClient.logout(
routerClient.sessionManager,
{
authUrlParams: Object.fromEntries(routerClient.searchParams)
}
);

const postLogoutRedirectURL = routerClient.getSearchParam(
'post_logout_redirect_url'
routerClient.sessionManager
);

let postLogoutRedirectURL = routerClient.getSearchParam('post_logout_redirect_url') || config.postLogoutRedirectURL;
if (postLogoutRedirectURL?.startsWith('/')) {
postLogoutRedirectURL = config.redirectURL + postLogoutRedirectURL;
}
if (postLogoutRedirectURL) {
await routerClient.sessionManager.setSessionItem(
'post_logout_redirect_url',
postLogoutRedirectURL
);
authUrl.searchParams.set('redirect', postLogoutRedirectURL);
}

return routerClient.redirect(authUrl.toString());
Expand Down

0 comments on commit 9509ac4

Please sign in to comment.