@uniquei/react
v1.0.9
Published
A lightweight TypeScript library for handling **Single Sign-On (SSO)** authentication in browser environments. It manages tokens, provides user fetching, and supports login/logout flows.
Readme
AuthService
A lightweight TypeScript library for handling Single Sign-On (SSO) authentication in browser environments.
It manages tokens, provides user fetching, and supports login/logout flows.
Installation
npm install @uniquei/react
# or
yarn add @uniquei/react
---
## API
AuthService.init(): void
Checks if a token exists in the URL query string.
If found, saves it to localStorage and cleans up the URL.
AuthService.login(): void
Redirects the user to the SSO login page.
After successful login, the server will redirect back with a token in the URL.
AuthService.logout(): void
Removes the stored token from localStorage and logs out the user.
AuthService.getUser(): Promise<User | null>
Fetches the currently authenticated user's data from the API.
Returns:
User object if authenticated
null if no valid token is present
Types
export type User = {
id: string;
name: string;
username: string;
email: string;
bio: string;
avatar: string;
createdAt: string;
};