@clicktap/state 0.11.0 → 0.11.1
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/index.esm.js +8 -7
- package/package.json +3 -4
- package/src/auth/AuthProvider.d.ts +6 -140
package/index.esm.js
CHANGED
|
@@ -466,16 +466,20 @@ var authMachine = setup({
|
|
|
466
466
|
}
|
|
467
467
|
});
|
|
468
468
|
|
|
469
|
-
var AuthContext = /*#__PURE__*/createContext(
|
|
469
|
+
var AuthContext = /*#__PURE__*/createContext(undefined);
|
|
470
470
|
var useAuth = function useAuth() {
|
|
471
471
|
var actor = useContext(AuthContext);
|
|
472
|
+
if (!actor) return {
|
|
473
|
+
authActor: undefined,
|
|
474
|
+
isLoggedIn: false
|
|
475
|
+
};
|
|
472
476
|
var _useState = useState(actor.getSnapshot().value === 'loggedIn'),
|
|
473
477
|
isLoggedIn = _useState[0],
|
|
474
|
-
|
|
478
|
+
setIsLoggedIn = _useState[1];
|
|
475
479
|
useEffect(function () {
|
|
476
480
|
var subscription = actor.subscribe(function (observer) {
|
|
477
481
|
if (observer.value === 'loggedIn' || observer.value === 'loggedOut') {
|
|
478
|
-
|
|
482
|
+
setIsLoggedIn(observer.value === 'loggedIn');
|
|
479
483
|
}
|
|
480
484
|
});
|
|
481
485
|
return function () {
|
|
@@ -487,9 +491,6 @@ var useAuth = function useAuth() {
|
|
|
487
491
|
isLoggedIn: isLoggedIn
|
|
488
492
|
};
|
|
489
493
|
};
|
|
490
|
-
var useUser = function useUser() {
|
|
491
|
-
return useContext(AuthContext).getSnapshot().context.user;
|
|
492
|
-
};
|
|
493
494
|
/**
|
|
494
495
|
* runs on server side as part of withAuth HOF
|
|
495
496
|
*
|
|
@@ -1003,4 +1004,4 @@ function ToastProvider(_ref) {
|
|
|
1003
1004
|
});
|
|
1004
1005
|
}
|
|
1005
1006
|
|
|
1006
|
-
export { AuthContext, AuthProvider, ToastContext, ToastProvider, authMachine, getAuth, timerMachine, toastMachine, useAuth, useToast
|
|
1007
|
+
export { AuthContext, AuthProvider, ToastContext, ToastProvider, authMachine, getAuth, timerMachine, toastMachine, useAuth, useToast };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clicktap/state",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Clicktap",
|
|
6
6
|
"description": "A state management library for Clicktap reference frontend.",
|
|
@@ -19,10 +19,9 @@
|
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"next": "^13.4.6",
|
|
21
21
|
"react": "^18.2.0",
|
|
22
|
-
"xstate": "^
|
|
22
|
+
"xstate": "^5.5.2",
|
|
23
23
|
"@xstate/immer": "^0.3.3",
|
|
24
|
-
"@xstate/
|
|
25
|
-
"@xstate/react": "^3.2.2",
|
|
24
|
+
"@xstate/react": "^4.0.3",
|
|
26
25
|
"cookie": "^0.5.0",
|
|
27
26
|
"axios": "^1.5.0",
|
|
28
27
|
"framer-motion": "^10.16.4"
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Actor, InspectionEvent, Observer } from 'xstate';
|
|
3
3
|
import { authMachine } from './auth';
|
|
4
|
+
export interface AuthContextType {
|
|
5
|
+
authActor: Actor<typeof authMachine> | undefined;
|
|
6
|
+
isLoggedIn: boolean;
|
|
7
|
+
}
|
|
4
8
|
export declare const AuthContext: import("react").Context<Actor<import("xstate").StateMachine<import("./auth").AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
|
|
5
9
|
[x: string]: import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
|
|
6
10
|
type: string;
|
|
@@ -135,146 +139,8 @@ export declare const AuthContext: import("react").Context<Actor<import("xstate")
|
|
|
135
139
|
}, {
|
|
136
140
|
type: string;
|
|
137
141
|
params: import("xstate").NonReducibleUnknown;
|
|
138
|
-
}, string, string
|
|
139
|
-
export declare const useAuth: () =>
|
|
140
|
-
authActor: Actor<import("xstate").StateMachine<import("./auth").AuthMachineContext, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
|
|
141
|
-
[x: string]: import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
|
|
142
|
-
type: string;
|
|
143
|
-
accessToken: string;
|
|
144
|
-
}, {
|
|
145
|
-
context: import("./auth").AuthMachineContext;
|
|
146
|
-
}>, {
|
|
147
|
-
[k: string]: unknown;
|
|
148
|
-
type: string;
|
|
149
|
-
}> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
|
|
150
|
-
type: string;
|
|
151
|
-
accessToken: string;
|
|
152
|
-
}, {
|
|
153
|
-
context: import("./auth").AuthMachineContext;
|
|
154
|
-
username: string;
|
|
155
|
-
password: string;
|
|
156
|
-
}>, {
|
|
157
|
-
[k: string]: unknown;
|
|
158
|
-
type: string;
|
|
159
|
-
}> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<{
|
|
160
|
-
type: string;
|
|
161
|
-
}, {
|
|
162
|
-
context: import("./auth").AuthMachineContext;
|
|
163
|
-
}>, {
|
|
164
|
-
[k: string]: unknown;
|
|
165
|
-
type: string;
|
|
166
|
-
}> | undefined;
|
|
167
|
-
}, {
|
|
168
|
-
src: "refreshAccessToken";
|
|
169
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
170
|
-
type: string;
|
|
171
|
-
accessToken: string;
|
|
172
|
-
}, {
|
|
173
|
-
context: import("./auth").AuthMachineContext;
|
|
174
|
-
}>;
|
|
175
|
-
id: string | undefined;
|
|
176
|
-
} | {
|
|
177
|
-
src: "authenticate";
|
|
178
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
179
|
-
type: string;
|
|
180
|
-
accessToken: string;
|
|
181
|
-
}, {
|
|
182
|
-
context: import("./auth").AuthMachineContext;
|
|
183
|
-
username: string;
|
|
184
|
-
password: string;
|
|
185
|
-
}>;
|
|
186
|
-
id: string | undefined;
|
|
187
|
-
} | {
|
|
188
|
-
src: "unauthenticate";
|
|
189
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
190
|
-
type: string;
|
|
191
|
-
}, {
|
|
192
|
-
context: import("./auth").AuthMachineContext;
|
|
193
|
-
}>;
|
|
194
|
-
id: string | undefined;
|
|
195
|
-
}, {
|
|
196
|
-
type: "setUserContext";
|
|
197
|
-
params: import("xstate").NonReducibleUnknown;
|
|
198
|
-
} | {
|
|
199
|
-
type: "unsetUserContext";
|
|
200
|
-
params: import("xstate").NonReducibleUnknown;
|
|
201
|
-
} | {
|
|
202
|
-
type: "setAccessToken";
|
|
203
|
-
params: import("xstate").NonReducibleUnknown;
|
|
204
|
-
} | {
|
|
205
|
-
type: "unsetRefreshToken";
|
|
206
|
-
params: import("xstate").NonReducibleUnknown;
|
|
207
|
-
} | {
|
|
208
|
-
type: "setIgnoreRefreshToken";
|
|
209
|
-
params: import("xstate").NonReducibleUnknown;
|
|
210
|
-
} | {
|
|
211
|
-
type: "addError";
|
|
212
|
-
params: import("xstate").NonReducibleUnknown;
|
|
213
|
-
} | {
|
|
214
|
-
type: "clearErrors";
|
|
215
|
-
params: import("xstate").NonReducibleUnknown;
|
|
216
|
-
}, {
|
|
217
|
-
type: string;
|
|
218
|
-
params: import("xstate").NonReducibleUnknown;
|
|
219
|
-
}, string, "refreshing" | "authenticating" | "loggedIn" | "loggedOut" | "unauthenticating", string, {
|
|
220
|
-
initialContext: Partial<import("./auth").AuthMachineContext>;
|
|
221
|
-
initialState?: string | undefined;
|
|
222
|
-
}, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, import("./auth").RefreshTokenEvent | import("./auth").LoginEvent | import("./auth").LogoutEvent | import("./auth").ClearErrorsEvent | import("xstate").DoneActorEvent<import("./auth").AuthenticateSuccessEvent> | import("xstate").DoneActorEvent<import("./auth").RefreshTokenSuccessEvent>, {
|
|
223
|
-
src: "refreshAccessToken";
|
|
224
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
225
|
-
type: string;
|
|
226
|
-
accessToken: string;
|
|
227
|
-
}, {
|
|
228
|
-
context: import("./auth").AuthMachineContext;
|
|
229
|
-
}>;
|
|
230
|
-
id: string | undefined;
|
|
231
|
-
} | {
|
|
232
|
-
src: "authenticate";
|
|
233
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
234
|
-
type: string;
|
|
235
|
-
accessToken: string;
|
|
236
|
-
}, {
|
|
237
|
-
context: import("./auth").AuthMachineContext;
|
|
238
|
-
username: string;
|
|
239
|
-
password: string;
|
|
240
|
-
}>;
|
|
241
|
-
id: string | undefined;
|
|
242
|
-
} | {
|
|
243
|
-
src: "unauthenticate";
|
|
244
|
-
logic: import("xstate").PromiseActorLogic<{
|
|
245
|
-
type: string;
|
|
246
|
-
}, {
|
|
247
|
-
context: import("./auth").AuthMachineContext;
|
|
248
|
-
}>;
|
|
249
|
-
id: string | undefined;
|
|
250
|
-
}, {
|
|
251
|
-
type: "setUserContext";
|
|
252
|
-
params: import("xstate").NonReducibleUnknown;
|
|
253
|
-
} | {
|
|
254
|
-
type: "unsetUserContext";
|
|
255
|
-
params: import("xstate").NonReducibleUnknown;
|
|
256
|
-
} | {
|
|
257
|
-
type: "setAccessToken";
|
|
258
|
-
params: import("xstate").NonReducibleUnknown;
|
|
259
|
-
} | {
|
|
260
|
-
type: "unsetRefreshToken";
|
|
261
|
-
params: import("xstate").NonReducibleUnknown;
|
|
262
|
-
} | {
|
|
263
|
-
type: "setIgnoreRefreshToken";
|
|
264
|
-
params: import("xstate").NonReducibleUnknown;
|
|
265
|
-
} | {
|
|
266
|
-
type: "addError";
|
|
267
|
-
params: import("xstate").NonReducibleUnknown;
|
|
268
|
-
} | {
|
|
269
|
-
type: "clearErrors";
|
|
270
|
-
params: import("xstate").NonReducibleUnknown;
|
|
271
|
-
}, {
|
|
272
|
-
type: string;
|
|
273
|
-
params: import("xstate").NonReducibleUnknown;
|
|
274
|
-
}, string, string>>>;
|
|
275
|
-
isLoggedIn: boolean;
|
|
276
|
-
};
|
|
277
|
-
export declare const useUser: () => Record<string, any> | null;
|
|
142
|
+
}, string, string>>> | undefined>;
|
|
143
|
+
export declare const useAuth: () => AuthContextType;
|
|
278
144
|
type AuthOptions = {
|
|
279
145
|
inspect: Observer<InspectionEvent> | undefined;
|
|
280
146
|
endpoints: {
|