useSignOut
Overview
The useSignOut
hook allows users to securely log out of their account by invalidating their session on the server. This hook integrates with Replyke’s authentication system and ensures proper session termination.
Usage Example
import { useSignOut } from "@replyke/react-js";
function SignOutButton() {
const signOut = useSignOut();
const handleSignOut = async () => {
try {
await signOut({
refreshToken: "user-refresh-token", // Replace with the actual refresh token
});
console.log("User signed out successfully");
} catch (error) {
console.error("Sign-out failed:", error.message);
}
};
return <button onClick={handleSignOut}>Sign Out</button>;
}
Parameters & Returns
Parameters
The hook returns a function that accepts an object with the following fields:
Parameter | Type | Required | Description |
---|---|---|---|
refreshToken | string | Yes | The refresh token for the user session. React Native apps must pass this token to sign out, as it is not managed automatically. React apps manage everything via cookies and do not need to provide this token explicitly. |
Returns
The function does not return a value but ensures the user session is invalidated on the server upon successful execution.