@@ -2,22 +2,22 @@ import { assign, createMachine } from "xstate"
2
2
import * as API from "../../api"
3
3
import * as Types from "../../api/types"
4
4
5
- export interface UserContext {
5
+ export interface AuthContext {
6
6
getUserError ?: Error | unknown
7
7
authError ?: Error | unknown
8
8
me ?: Types . UserResponse
9
9
}
10
10
11
- export type UserEvent = { type : "SIGN_OUT" } | { type : "SIGN_IN" ; email : string ; password : string }
11
+ export type AuthEvent = { type : "SIGN_OUT" } | { type : "SIGN_IN" ; email : string ; password : string }
12
12
13
- export const userMachine =
13
+ export const authMachine =
14
14
/** @xstate -layout N4IgpgJg5mDOIC5QFdZgE4GUAuBDbYAdLAJZQB2kA8stgMSYCSA4gHID6jrioADgPalsJfuR4gAHogDM0gJyEATAHYAbNIAscxdunKArKo0AaEAE9EG+YX0BGABz3FD6atsbbc5QF9vp1Bg4+ESkFCTkUIzkdBCiROEAbvwA1iFk5FHiAkIiYkiSiHIADITSOvbSRRqq2m7StqYWCIr2+ja2tvVV+vqaRVW+-mhYeATE6eGR0Rjo-OiEvAA2+ABmcwC24xSZ+dkkwqLiUghlyoRF+opayq4X+sqK+o2Il6qEcq5y+hrfjt+qgxAARGwUIMGwwgiAFVhjE4oREikiOCALJgLKCfa5I4yIyEZTFZQaezFK5lPTPBC2IqKUqKC4EjqqKrFOSA4FBMbgyFQGEYOgzOYLZbYNboTao9G7TEHPKgY7SewlTQ3dRyVQ6GpVSmKMqEIz2ZRKjrKIqqJzs4actIUSBRBgsDhUKEAFQxOUO+WOhvshA0ahualsqnu8kpthUhGplVUIa+rUq9ktgVGNvIkxo9FilAR5CSqS25Ez7qxnvliCMGlK1Tk6vN5p+T3ML0Ub2U7iKXmcGg8tmTILGoXTEUzAvQs3mS1WG0LxelHrlBQQIbasc7aiKtnbV3sOpaUZXBjkwd1A0B5H4EDg4g5qcL1FoJdlOIQdlpH2qhmJzJ+DWbCB7WxSmUIl2wJM0CSTPwgStO8h0mHY+BlbEvReICaSMbQflkU0fkpHtfS3MC3C+aR9ENfR+2tMEwAhSY+XQJ8UPLACziVS5TXKAxPDI8MaSjIojSqPQezNRUqLg9I7UXPZn1Q5dqn1CMNEEi4HAecNIyVGoIweVQDH0tloNvUF4JHR951LRdvQcc4PCcAx12-fDOnOeRTU7C4SXsPtjNg4ImLLJddUIdiVBpOQKJ4psmh0ASQOPRUiI8RRfF8IA */
15
15
createMachine (
16
16
{
17
- tsTypes : { } as import ( "./userXService .typegen" ) . Typegen0 ,
17
+ tsTypes : { } as import ( "./authXService .typegen" ) . Typegen0 ,
18
18
schema : {
19
- context : { } as UserContext ,
20
- events : { } as UserEvent ,
19
+ context : { } as AuthContext ,
20
+ events : { } as AuthEvent ,
21
21
services : { } as {
22
22
getMe : {
23
23
data : Types . UserResponse
@@ -32,13 +32,13 @@ export const userMachine =
32
32
getUserError : undefined ,
33
33
authError : undefined ,
34
34
} ,
35
- id : "userState " ,
35
+ id : "authState " ,
36
36
initial : "gettingUser" ,
37
37
states : {
38
38
signedOut : {
39
39
on : {
40
40
SIGN_IN : {
41
- target : "#userState .signingIn" ,
41
+ target : "#authState .signingIn" ,
42
42
} ,
43
43
} ,
44
44
} ,
@@ -48,14 +48,14 @@ export const userMachine =
48
48
id : "signIn" ,
49
49
onDone : [
50
50
{
51
- target : "#userState .gettingUser" ,
51
+ target : "#authState .gettingUser" ,
52
52
actions : "clearAuthError" ,
53
53
} ,
54
54
] ,
55
55
onError : [
56
56
{
57
57
actions : "assignAuthError" ,
58
- target : "#userState .signedOut" ,
58
+ target : "#authState .signedOut" ,
59
59
} ,
60
60
] ,
61
61
} ,
@@ -68,13 +68,13 @@ export const userMachine =
68
68
onDone : [
69
69
{
70
70
actions : [ "assignMe" , "clearGetUserError" ] ,
71
- target : "#userState .signedIn" ,
71
+ target : "#authState .signedIn" ,
72
72
} ,
73
73
] ,
74
74
onError : [
75
75
{
76
76
actions : "assignGetUserError" ,
77
- target : "#userState .signedOut" ,
77
+ target : "#authState .signedOut" ,
78
78
} ,
79
79
] ,
80
80
} ,
@@ -83,7 +83,7 @@ export const userMachine =
83
83
signedIn : {
84
84
on : {
85
85
SIGN_OUT : {
86
- target : "#userState .signingOut" ,
86
+ target : "#authState .signingOut" ,
87
87
} ,
88
88
} ,
89
89
} ,
@@ -94,13 +94,13 @@ export const userMachine =
94
94
onDone : [
95
95
{
96
96
actions : [ "unassignMe" , "clearAuthError" ] ,
97
- target : "#userState .signedOut" ,
97
+ target : "#authState .signedOut" ,
98
98
} ,
99
99
] ,
100
100
onError : [
101
101
{
102
102
actions : "assignAuthError" ,
103
- target : "#userState .signedIn" ,
103
+ target : "#authState .signedIn" ,
104
104
} ,
105
105
] ,
106
106
} ,
@@ -120,21 +120,21 @@ export const userMachine =
120
120
assignMe : assign ( {
121
121
me : ( _ , event ) => event . data ,
122
122
} ) ,
123
- unassignMe : assign ( ( context : UserContext ) => ( {
123
+ unassignMe : assign ( ( context : AuthContext ) => ( {
124
124
...context ,
125
125
me : undefined ,
126
126
} ) ) ,
127
127
assignGetUserError : assign ( {
128
128
getUserError : ( _ , event ) => event . data ,
129
129
} ) ,
130
- clearGetUserError : assign ( ( context : UserContext ) => ( {
130
+ clearGetUserError : assign ( ( context : AuthContext ) => ( {
131
131
...context ,
132
132
getUserError : undefined ,
133
133
} ) ) ,
134
134
assignAuthError : assign ( {
135
135
authError : ( _ , event ) => event . data ,
136
136
} ) ,
137
- clearAuthError : assign ( ( context : UserContext ) => ( {
137
+ clearAuthError : assign ( ( context : AuthContext ) => ( {
138
138
...context ,
139
139
authError : undefined ,
140
140
} ) ) ,
0 commit comments