nextauthz 1.3.17 → 1.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +1 -1
- package/readme.md +10 -9
- package/src/AuthProvider.tsx +3 -0
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ type AuthContextType<UserType extends User$1 = User$1> = {
|
|
|
10
10
|
user: UserType | null;
|
|
11
11
|
role: string | null;
|
|
12
12
|
isAuthenticated: boolean;
|
|
13
|
+
isAuthChecked: boolean;
|
|
13
14
|
login: (tokens: Record<string, string>, userData?: UserType, role?: string) => void;
|
|
14
15
|
logout: () => void;
|
|
15
16
|
setUser: (user: UserType | null) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ type AuthContextType<UserType extends User$1 = User$1> = {
|
|
|
10
10
|
user: UserType | null;
|
|
11
11
|
role: string | null;
|
|
12
12
|
isAuthenticated: boolean;
|
|
13
|
+
isAuthChecked: boolean;
|
|
13
14
|
login: (tokens: Record<string, string>, userData?: UserType, role?: string) => void;
|
|
14
15
|
logout: () => void;
|
|
15
16
|
setUser: (user: UserType | null) => void;
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,7 @@ function createAuthContext(option) {
|
|
|
74
74
|
setUser,
|
|
75
75
|
setRole,
|
|
76
76
|
resetAuth,
|
|
77
|
+
isAuthChecked,
|
|
77
78
|
isAuthenticated,
|
|
78
79
|
setAuth,
|
|
79
80
|
setAuthChecked
|
|
@@ -119,6 +120,7 @@ function createAuthContext(option) {
|
|
|
119
120
|
user,
|
|
120
121
|
role,
|
|
121
122
|
isAuthenticated,
|
|
123
|
+
isAuthChecked,
|
|
122
124
|
login,
|
|
123
125
|
logout,
|
|
124
126
|
setUser: (u) => setUser(u),
|
package/dist/index.mjs
CHANGED
|
@@ -47,6 +47,7 @@ function createAuthContext(option) {
|
|
|
47
47
|
setUser,
|
|
48
48
|
setRole,
|
|
49
49
|
resetAuth,
|
|
50
|
+
isAuthChecked,
|
|
50
51
|
isAuthenticated,
|
|
51
52
|
setAuth,
|
|
52
53
|
setAuthChecked
|
|
@@ -92,6 +93,7 @@ function createAuthContext(option) {
|
|
|
92
93
|
user,
|
|
93
94
|
role,
|
|
94
95
|
isAuthenticated,
|
|
96
|
+
isAuthChecked,
|
|
95
97
|
login,
|
|
96
98
|
logout,
|
|
97
99
|
setUser: (u) => setUser(u),
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -49,19 +49,20 @@ export default App
|
|
|
49
49
|
```bash
|
|
50
50
|
import { useAuth } from 'nextauthz'
|
|
51
51
|
|
|
52
|
-
const { user, role, login, logout, setUser, isAuthenticated } = useAuth()
|
|
52
|
+
const { user, role, login, logout, setUser, isAuthenticated, isAuthChecked } = useAuth()
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
Available Properties
|
|
56
56
|
|
|
57
|
-
| Name | Type
|
|
58
|
-
| ----------------- |
|
|
59
|
-
| `user` | `User
|
|
60
|
-
| `role` | `string
|
|
61
|
-
| `isAuthenticated` | `boolean`
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
57
|
+
| Name | Type | Description |
|
|
58
|
+
| ----------------- | ------------------------------------ | ------------------------------------------------------------- |
|
|
59
|
+
| `user` | `User \| null` | Current authenticated user |
|
|
60
|
+
| `role` | `string \| null` | User role |
|
|
61
|
+
| `isAuthenticated` | `boolean` | True if the user is logged in |
|
|
62
|
+
| `isAuthChecked` | `boolean` | True if auth state has finished restoring from storage/token |
|
|
63
|
+
| `login` | `(tokens, userData?, role?) => void` | Logs in a user, saves tokens, and optionally sets user + role |
|
|
64
|
+
| `logout` | `() => void` | Clears auth tokens and resets state |
|
|
65
|
+
| `setUser` | `(user: User \| null) => void` | Update user state manually |
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
Example: Logging in
|
package/src/AuthProvider.tsx
CHANGED
|
@@ -12,6 +12,7 @@ export type AuthContextType<UserType extends User = User> = {
|
|
|
12
12
|
user: UserType | null
|
|
13
13
|
role: string | null
|
|
14
14
|
isAuthenticated: boolean
|
|
15
|
+
isAuthChecked: boolean
|
|
15
16
|
login: (tokens: Record<string, string>, userData?: UserType, role?: string) => void
|
|
16
17
|
logout: () => void
|
|
17
18
|
setUser: (user: UserType | null) => void
|
|
@@ -45,6 +46,7 @@ export function createAuthContext<UserType extends User = User>(option?: {
|
|
|
45
46
|
setUser,
|
|
46
47
|
setRole,
|
|
47
48
|
resetAuth,
|
|
49
|
+
isAuthChecked,
|
|
48
50
|
isAuthenticated,
|
|
49
51
|
setAuth,
|
|
50
52
|
setAuthChecked,
|
|
@@ -111,6 +113,7 @@ export function createAuthContext<UserType extends User = User>(option?: {
|
|
|
111
113
|
user: user as UserType | null,
|
|
112
114
|
role,
|
|
113
115
|
isAuthenticated,
|
|
116
|
+
isAuthChecked,
|
|
114
117
|
login,
|
|
115
118
|
logout,
|
|
116
119
|
setUser: (u) => setUser(u),
|