@abaxx_tech/v-integration-react 1.1.2-dev.1 → 1.1.2-dev.3
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/README.md +61 -0
- package/dist/v-integration-react.d.ts +5 -0
- package/dist/v-integration-react.js +516 -504
- package/dist/v-integration-react.umd.cjs +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
- **Error Handling**: Comprehensive error handling and user feedback.
|
|
12
12
|
- **Customizable Styling**: Full control over colors, sizes, and text with support for both Tailwind classes and hex colors.
|
|
13
13
|
- **Background Authentication Service**: Automatic token management and authentication flow handling.
|
|
14
|
+
- **State Reset**: Built-in functionality to reset authentication state back to initial values.
|
|
14
15
|
<br/><br/>
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
@@ -129,6 +130,41 @@ const MyComponent = () => {
|
|
|
129
130
|
return <div>Not authenticated</div>;
|
|
130
131
|
};
|
|
131
132
|
```
|
|
133
|
+
|
|
134
|
+
### 4. Reset Authentication State
|
|
135
|
+
Use the `useVerifierReset` hook to reset the authentication state back to initial values:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
139
|
+
|
|
140
|
+
const LogoutButton = () => {
|
|
141
|
+
const resetState = useVerifierReset();
|
|
142
|
+
|
|
143
|
+
const handleLogout = () => {
|
|
144
|
+
resetState(); // Resets all authentication state to initial values
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<button onClick={handleLogout}>
|
|
149
|
+
Logout & Reset
|
|
150
|
+
</button>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default LogoutButton;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**What gets reset:**
|
|
158
|
+
- `identity` → `""`
|
|
159
|
+
- `authRequestId` → `""`
|
|
160
|
+
- `isAuthenticating` → `false`
|
|
161
|
+
- `codeVerifier` → `""`
|
|
162
|
+
- `codeChallenge` → `""`
|
|
163
|
+
- `authCode` → `""`
|
|
164
|
+
- `authRequestIdExpires` → `new Date()`
|
|
165
|
+
- `token` → `null`
|
|
166
|
+
- `authError` → `null`
|
|
167
|
+
|
|
132
168
|
<br/><br/>
|
|
133
169
|
|
|
134
170
|
## Components
|
|
@@ -237,6 +273,31 @@ The authentication context provides access to all authentication-related state a
|
|
|
237
273
|
| `authCode` | `string` | Authorization code from successful auth |
|
|
238
274
|
| `token` | `string \| null` | Authentication token |
|
|
239
275
|
| `authError` | `string \| null` | Authentication error message |
|
|
276
|
+
| `resetState` | `() => void` | Function to reset all state to initial values |
|
|
277
|
+
|
|
278
|
+
### Reset Functionality
|
|
279
|
+
The library provides a built-in reset function to clear all authentication state:
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
import { useContext } from 'react';
|
|
283
|
+
import { VContext, useVerifierReset } from "@abaxx_tech/v-integration-react";
|
|
284
|
+
|
|
285
|
+
const MyComponent = () => {
|
|
286
|
+
const { resetState: resetStateFromContext } = useContext(VContext);
|
|
287
|
+
const resetState = useVerifierReset();
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<>
|
|
291
|
+
<button onClick={resetStateFromContext}>
|
|
292
|
+
Reset Authentication from context
|
|
293
|
+
</button>
|
|
294
|
+
<button onClick={resetState}>
|
|
295
|
+
Reset Authentication
|
|
296
|
+
</button>
|
|
297
|
+
</>
|
|
298
|
+
);
|
|
299
|
+
};
|
|
300
|
+
```
|
|
240
301
|
|
|
241
302
|
## Authentication Flow
|
|
242
303
|
|
|
@@ -7,6 +7,10 @@ declare type Props = {
|
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
export declare function resetVerifierStateUnsafe(ctx: default_2.ContextType<typeof VContext>): void;
|
|
11
|
+
|
|
12
|
+
export declare function useVerifierReset(): () => void;
|
|
13
|
+
|
|
10
14
|
export declare const VContext: default_2.Context<VContextObj>;
|
|
11
15
|
|
|
12
16
|
export declare type VContextObj = {
|
|
@@ -30,6 +34,7 @@ export declare type VContextObj = {
|
|
|
30
34
|
setToken: default_2.Dispatch<default_2.SetStateAction<string | null>>;
|
|
31
35
|
authError: string | null;
|
|
32
36
|
setAuthError: default_2.Dispatch<default_2.SetStateAction<string | null>>;
|
|
37
|
+
resetState: () => void;
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
export declare const VContextProvider: default_2.FC<Props>;
|