Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add post logout redirect url #87

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/components/LogoutLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ 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}) {
let params = new URLSearchParams();
let paramsObj = {};
if (postLogoutRedirectURL != null)
paramsObj.post_logout_redirect_url = postLogoutRedirectURL;

for (const key in paramsObj) params.append(key, paramsObj[key]);

return (
<a href={`${config.apiPath}/logout`} {...props}>
<a
href={`${config.apiPath}/logout${params ? `?${params.toString()}` : ''}`}
nip10 marked this conversation as resolved.
Show resolved Hide resolved
{...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
@@ -1,7 +1,21 @@
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);
};