diff --git a/src/components/LogoutLink.js b/src/components/LogoutLink.js index 73ef573..c236c33 100644 --- a/src/components/LogoutLink.js +++ b/src/components/LogoutLink.js @@ -4,6 +4,7 @@ import {config} from '../config/index'; /** * @typedef {Object} PropsType * @prop {React.ReactNode} children + * @prop {string} [postLogoutRedirectURL] * * @typedef {PropsType & React.AnchorHTMLAttributes} Props */ @@ -11,9 +12,16 @@ import {config} from '../config/index'; /** * @param {Props} props */ -export function LogoutLink({children, ...props}) { +export function LogoutLink({children, postLogoutRedirectURL, ...props}) { return ( - + {children} ); diff --git a/src/handlers/logout.js b/src/handlers/logout.js index 4b9c076..ae15cf8 100644 --- a/src/handlers/logout.js +++ b/src/handlers/logout.js @@ -6,8 +6,22 @@ import RouterClient from '../routerClients/RouterClient'; */ export const logout = async (routerClient) => { const authUrl = await routerClient.kindeClient.logout( - routerClient.sessionManager + routerClient.sessionManager, + { + authUrlParams: Object.fromEntries(routerClient.searchParams) + } ); + const postLogoutRedirectURL = routerClient.getSearchParam( + 'post_logout_redirect_url' + ); + + if (postLogoutRedirectURL) { + await routerClient.sessionManager.setSessionItem( + 'post_logout_redirect_url', + postLogoutRedirectURL + ); + } + routerClient.redirect(authUrl.toString()); };