bjerkio/oidc-react

Signout Option

okandonmez opened this issue ยท 4 comments

Hello!

I succesfully implemented login option as below. Thanks for such a useful library. But I could not find any information for the logout option in the documents. How can i implement logout option for the following use.

const oidcConfig = {
    onSignIn: (user) => {
        console.log(user);
    },
    authority: 'https://myauthority',
    clientId: 'myclient',
    redirectUri: 'http://localhost:3000/sth',
};

...

<AuthProvider {...oidcConfig}>
    {renderMyForm(true)}
</AuthProvider>

Hello ๐Ÿ‘‹

Thank you for using oidc-react and thank you so much for opening this issue. Depending on how you've your React setup is, you can use either the useAuth hook or HOC. Inside each you'll find an logout function that can be used for this :)

Example with the useAuth hook:

const LogoutButton = () => {
	const { signOut } = useAuth();
	return <Button onClick={() => signOut()}>Logout</Button>
}

The AuthContext has a few functions that I recommend checking out!

Did that help you out?

Thank you very much for the sample. I implemented it successfully. Maybe i need to ask one more question. Is it possible to prevent automatic signin? For example, I want to trigger the signin when a button is clicked, but now the page is logged in as it is rendered.

You can set autoSignIn to false in your oidcConfig to achieve that :)

Thank you very much for your quick answers. I accomplished all that I had planned. Appreciated :)