useAuthUser¶
Import¶
Function Signature¶
useAuthUser<T
>(): T | null
Auth User Data React Hook
Call the hook, to get the authenticated user data into your React Component
This uses the context data to determine the user data
Type Parameters¶
Name | Description |
---|---|
T |
Type of User State Object |
Returns¶
T
| null
React Hook with user state functionality.
If the user is authenticated, then user data is returned.
If the user is not authenticated, then null
is returned.
Example¶
Here is an example of JavaScript
import useAuthUser from 'react-auth-kit/hooks/useAuthUser'
const Component = () => {
const authUser = useAuthUser()
const name = authUser.name;
const uuid = authUser.uuid;
...
}
import useAuthUser from 'react-auth-kit/hooks/useAuthUser'
interface IUserData {
name: string;
uuid: string;
};
const Component = () => {
const authUser = useAuthUser<IUserData>()
const name = authUser.name;
const uuid = authUser.uuid;
...
}
Throws¶
AuthError Thrown if the Hook is used outside the Provider Scope.
Defined in¶
— 🔑 —
React Auth Kit is MIT License code