Skip to content

Commit

Permalink
Merge pull request #87 from nip10/feat/logout-redirect-url
Browse files Browse the repository at this point in the history
feat: add post logout redirect url
  • Loading branch information
DaveOrDead authored Dec 19, 2023
2 parents f356576 + 5a395e4 commit 3bf9fdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/components/LogoutLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import {config} from '../config/index';
/**
* @typedef {Object} PropsType
* @prop {React.ReactNode} children
* @prop {string} [postLogoutRedirectURL]
*
* @typedef {PropsType & React.AnchorHTMLAttributes<HTMLAnchorElement>} Props
*/

/**
* @param {Props} props
*/
export function LogoutLink({children, ...props}) {
export function LogoutLink({children, postLogoutRedirectURL, ...props}) {
return (
<a href={`${config.apiPath}/logout`} {...props}>
<a
href={`${config.apiPath}/logout${
postLogoutRedirectURL
? `?post_logout_redirect_url=${postLogoutRedirectURL}`
: ''}
`}
{...props}
>
{children}
</a>
);
Expand Down
16 changes: 15 additions & 1 deletion src/handlers/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};

0 comments on commit 3bf9fdf

Please sign in to comment.