@abaxx_tech/v-integration-react 1.1.1 → 1.1.2-dev.2
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 -2
- package/dist/v-integration-react.d.ts +5 -3
- package/dist/v-integration-react.js +891 -890
- 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
|
|
@@ -31,7 +32,6 @@ import { VerifierProvider } from "@abaxx_tech/v-integration-react";
|
|
|
31
32
|
const App = () => {
|
|
32
33
|
return (
|
|
33
34
|
<VerifierProvider
|
|
34
|
-
appId={Number(import.meta.env.VITE_APP_ID)}
|
|
35
35
|
apiUrl={import.meta.env.VITE_API_URL}
|
|
36
36
|
clientId={import.meta.env.VITE_CLIENT_ID}
|
|
37
37
|
>
|
|
@@ -130,6 +130,41 @@ const MyComponent = () => {
|
|
|
130
130
|
return <div>Not authenticated</div>;
|
|
131
131
|
};
|
|
132
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
|
+
|
|
133
168
|
<br/><br/>
|
|
134
169
|
|
|
135
170
|
## Components
|
|
@@ -140,7 +175,6 @@ The main provider component that wraps your application and manages the authenti
|
|
|
140
175
|
#### Props:
|
|
141
176
|
| Prop | Type | Description |
|
|
142
177
|
| ------------- | ------------- | ------------- |
|
|
143
|
-
| `appId` | `string \| number` | Unique application ID |
|
|
144
178
|
| `apiUrl` | `string` | API URL for authentication |
|
|
145
179
|
| `clientId` | `string` | Client identifier |
|
|
146
180
|
| `children` | `ReactNode` | Child components to be wrapped |
|
|
@@ -239,6 +273,31 @@ The authentication context provides access to all authentication-related state a
|
|
|
239
273
|
| `authCode` | `string` | Authorization code from successful auth |
|
|
240
274
|
| `token` | `string \| null` | Authentication token |
|
|
241
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
|
+
```
|
|
242
301
|
|
|
243
302
|
## Authentication Flow
|
|
244
303
|
|
|
@@ -2,16 +2,18 @@ import { default as default_2 } from 'react';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
declare type Props = {
|
|
5
|
-
appId: string | number;
|
|
6
5
|
clientId: string;
|
|
7
6
|
apiUrl: string;
|
|
8
7
|
children: ReactNode;
|
|
9
8
|
};
|
|
10
9
|
|
|
10
|
+
export declare function resetVerifierStateUnsafe(ctx: React.ContextType<typeof VContext>): void;
|
|
11
|
+
|
|
12
|
+
export declare function useVerifierReset(): () => void;
|
|
13
|
+
|
|
11
14
|
export declare const VContext: default_2.Context<VContextObj>;
|
|
12
15
|
|
|
13
16
|
export declare type VContextObj = {
|
|
14
|
-
appId: string | number;
|
|
15
17
|
apiUrl: string;
|
|
16
18
|
clientId: string;
|
|
17
19
|
authRequestId: string;
|
|
@@ -32,6 +34,7 @@ export declare type VContextObj = {
|
|
|
32
34
|
setToken: default_2.Dispatch<default_2.SetStateAction<string | null>>;
|
|
33
35
|
authError: string | null;
|
|
34
36
|
setAuthError: default_2.Dispatch<default_2.SetStateAction<string | null>>;
|
|
37
|
+
resetState: () => void;
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
export declare const VContextProvider: default_2.FC<Props>;
|
|
@@ -78,7 +81,6 @@ export declare interface VerifierAuthQrProps {
|
|
|
78
81
|
export declare const VerifierProvider: default_2.FC<VerifierProviderProps>;
|
|
79
82
|
|
|
80
83
|
export declare interface VerifierProviderProps {
|
|
81
|
-
appId: string | number;
|
|
82
84
|
clientId: string;
|
|
83
85
|
apiUrl: string;
|
|
84
86
|
children: ReactNode;
|