From e158c318e74fc7e9e2ad9ea8b80bab73348aab2a Mon Sep 17 00:00:00 2001 From: nip10 Date: Mon, 6 Nov 2023 12:28:50 +0000 Subject: [PATCH 1/2] feat: add post logout redirect url --- src/components/LogoutLink.js | 15 +++++++++++++-- src/handlers/logout.js | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/LogoutLink.js b/src/components/LogoutLink.js index 73ef573..83e169d 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,19 @@ import {config} from '../config/index'; /** * @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 ( - + {children} ); diff --git a/src/handlers/logout.js b/src/handlers/logout.js index c36707f..7ed4979 100644 --- a/src/handlers/logout.js +++ b/src/handlers/logout.js @@ -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); }; From bab315097096556bc58831c7a7aed7a025303b43 Mon Sep 17 00:00:00 2001 From: nip10 Date: Mon, 11 Dec 2023 21:36:07 +0000 Subject: [PATCH 2/2] refactor: simplify url params --- src/components/LogoutLink.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/LogoutLink.js b/src/components/LogoutLink.js index 83e169d..c236c33 100644 --- a/src/components/LogoutLink.js +++ b/src/components/LogoutLink.js @@ -13,16 +13,13 @@ import {config} from '../config/index'; * @param {Props} 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 ( {children}