@clicktap/state 0.11.1 → 0.11.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/index.esm.js +8 -8
- package/package.json +1 -1
- package/src/auth/AuthProvider.d.ts +2 -2
package/index.esm.js
CHANGED
|
@@ -466,18 +466,18 @@ var authMachine = setup({
|
|
|
466
466
|
}
|
|
467
467
|
});
|
|
468
468
|
|
|
469
|
-
var AuthContext = /*#__PURE__*/createContext(
|
|
469
|
+
var AuthContext = /*#__PURE__*/createContext(createActor(authMachine));
|
|
470
470
|
var useAuth = function useAuth() {
|
|
471
|
-
var
|
|
472
|
-
if (!
|
|
473
|
-
authActor:
|
|
471
|
+
var authActor = useContext(AuthContext);
|
|
472
|
+
if (!authActor) return {
|
|
473
|
+
authActor: authActor,
|
|
474
474
|
isLoggedIn: false
|
|
475
475
|
};
|
|
476
|
-
var _useState = useState(
|
|
476
|
+
var _useState = useState(authActor.getSnapshot().value === 'loggedIn'),
|
|
477
477
|
isLoggedIn = _useState[0],
|
|
478
478
|
setIsLoggedIn = _useState[1];
|
|
479
479
|
useEffect(function () {
|
|
480
|
-
var subscription =
|
|
480
|
+
var subscription = authActor.subscribe(function (observer) {
|
|
481
481
|
if (observer.value === 'loggedIn' || observer.value === 'loggedOut') {
|
|
482
482
|
setIsLoggedIn(observer.value === 'loggedIn');
|
|
483
483
|
}
|
|
@@ -485,9 +485,9 @@ var useAuth = function useAuth() {
|
|
|
485
485
|
return function () {
|
|
486
486
|
subscription.unsubscribe();
|
|
487
487
|
};
|
|
488
|
-
}, [
|
|
488
|
+
}, [authActor]);
|
|
489
489
|
return {
|
|
490
|
-
authActor:
|
|
490
|
+
authActor: authActor,
|
|
491
491
|
isLoggedIn: isLoggedIn
|
|
492
492
|
};
|
|
493
493
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { Actor, InspectionEvent, Observer } from 'xstate';
|
|
3
3
|
import { authMachine } from './auth';
|
|
4
4
|
export interface AuthContextType {
|
|
5
|
-
authActor: Actor<typeof authMachine
|
|
5
|
+
authActor: Actor<typeof authMachine>;
|
|
6
6
|
isLoggedIn: boolean;
|
|
7
7
|
}
|
|
8
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>, {
|
|
@@ -139,7 +139,7 @@ export declare const AuthContext: import("react").Context<Actor<import("xstate")
|
|
|
139
139
|
}, {
|
|
140
140
|
type: string;
|
|
141
141
|
params: import("xstate").NonReducibleUnknown;
|
|
142
|
-
}, string, string
|
|
142
|
+
}, string, string>>>>;
|
|
143
143
|
export declare const useAuth: () => AuthContextType;
|
|
144
144
|
type AuthOptions = {
|
|
145
145
|
inspect: Observer<InspectionEvent> | undefined;
|