Peter Penzov
Peter Penzov

Reputation: 1682

Set logout link for react-oidc-context

I use this code to logout user:

const signOut: JwtAuthContextType['signOut'] = useCallback(() => {
        removeTokenStorageValue();
        removeGlobalHeaders(['Authorization']);
        setAuthState({
            authStatus: 'unauthenticated',
            isAuthenticated: false,
            user: null
        });
        auth.signoutRedirect();
    }, [removeTokenStorageValue]);

When I call it I'm redirected to http://host:8080/logout?id_token_hint=eyJraWQiOi.......

I need to set a custom logout url: http://host:8080/connect/logout?id_token_hint=eyJraWQiOi......

Do you know how I can configure this?

Upvotes: 2

Views: 121

Answers (3)

pratikpc
pratikpc

Reputation: 680

Given your use case and based on @raghvendra-n's answer, you could take advantage of post_logout_redirect_uri parameter.

const signOut: JwtAuthContextType['signOut'] = useCallback(() => {
        removeTokenStorageValue();
        removeGlobalHeaders(['Authorization']);
        setAuthState({
            authStatus: 'unauthenticated',
            isAuthenticated: false,
            user: null
        });
        auth.signoutRedirect({post_logout_redirect_uri: "http://host:8080/connect/logout"});
    }, [removeTokenStorageValue]);

What I would like to add, is as can be seen from the code, signoutRedirect needs an absolute path to the URL

Upvotes: 0

web developer
web developer

Reputation: 1

you can config like this.

const authConfig = {
  authority: "http://host:8080",
  client_id: "your-client-id",
  redirect_uri: "http://your-app.com/callback",
  post_logout_redirect_uri: "http://your-app.com/logout",
  response_type: "code",
  scope: "openid profile email",
};
const userManager = new UserManager(authConfig);

Upvotes: 0

Raghavendra N
Raghavendra N

Reputation: 5546

You can supply your custom logout url via post_logout_redirect_uri argument.

auth.signoutRedirect({post_logout_redirect_uri: '<your-custom-url>'})

Or you can also specify this in the oidc configuration:

const oidcConfig = {
  ...
  post_logout_redirect_uri: "<your-custom-url>",
  ...
};

Upvotes: 3

Related Questions