kinde-oss / kinde-auth-nextjs

Kinde NextJS SDK - authentication for server rendered apps
https://kinde.com/docs/developer-tools/nextjs-sdk/
MIT License
150 stars 20 forks source link

Feature request: Add dynamic post logout redirect urls #76

Closed DaveOrDead closed 8 months ago

DaveOrDead commented 11 months ago

Prerequisites

What is the problem you’re trying to solve?

In the same way that dynamic post login urls are allowed, it would be useful to allow the same for logout.

For example to allow both:

api/auth/logout?post_logout_redirect_uri=product1/login
api/auth/logout?post_logout_redirect_uri=product2/login

What solution would you like to see?

a post_logout_redirect_uri parameter that can be passed to the logout url something like

<Link
    href={{
        pathname: "/api/auth/logout",
        query: {
            post_logout_redirect_url: "/product2/login"
        }
    }}
>
    Log out
</Link>

Additional information

No response

bliongosari1 commented 11 months ago

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' );

if (postLogoutRedirectURL) { await routerClient.sessionManager.setSessionItem( 'post_logout_redirect_url', postLogoutRedirectURL ); }

routerClient.redirect(authUrl); };

Think this should do it for pages router, just need to add LogoutLink for app router