Skip to content

Commit 0bf9dee

Browse files
authored
chore(site): rename userXService to authXService (#924)
* chore(site): rename userXService to authXService * Rename contents of xService
1 parent 94ab6f3 commit 0bf9dee

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

site/src/components/Navbar/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { NavbarView } from "./NavbarView"
55

66
export const Navbar: React.FC = () => {
77
const xServices = useContext(XServiceContext)
8-
const [userState, userSend] = useActor(xServices.userXService)
9-
const { me } = userState.context
10-
const onSignOut = () => userSend("SIGN_OUT")
8+
const [authState, authSend] = useActor(xServices.authXService)
9+
const { me } = authState.context
10+
const onSignOut = () => authSend("SIGN_OUT")
1111

1212
return <NavbarView user={me} onSignOut={onSignOut} />
1313
}

site/src/components/Page/RequireAuth.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export interface RequireAuthProps {
1111

1212
export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
1313
const xServices = useContext(XServiceContext)
14-
const [userState] = useActor(xServices.userXService)
14+
const [authState] = useActor(xServices.authXService)
1515
const location = useLocation()
1616
const redirectTo = embedRedirect(location.pathname)
1717

18-
if (userState.matches("signedOut") || !userState.context.me) {
18+
if (authState.matches("signedOut") || !authState.context.me) {
1919
return <Navigate to={redirectTo} />
20-
} else if (userState.hasTag("loading")) {
20+
} else if (authState.hasTag("loading")) {
2121
return <FullScreenLoader />
2222
} else {
2323
return children

site/src/pages/cli-auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { XServiceContext } from "../xServices/StateContext"
88

99
export const CliAuthenticationPage: React.FC = () => {
1010
const xServices = useContext(XServiceContext)
11-
const [userState] = useActor(xServices.userXService)
12-
const { me } = userState.context
11+
const [authState] = useActor(xServices.authXService)
12+
const { me } = authState.context
1313

1414
const styles = useStyles()
1515

site/src/pages/login.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ export const SignInPage: React.FC = () => {
2424
const styles = useStyles()
2525
const location = useLocation()
2626
const xServices = useContext(XServiceContext)
27-
const [userState, userSend] = useActor(xServices.userXService)
28-
const isLoading = userState.hasTag("loading")
27+
const [authState, authSend] = useActor(xServices.authXService)
28+
const isLoading = authState.hasTag("loading")
2929
const redirectTo = retrieveRedirect(location.search)
30-
const authErrorMessage = userState.context.authError ? (userState.context.authError as Error).message : undefined
30+
const authErrorMessage = authState.context.authError ? (authState.context.authError as Error).message : undefined
3131

3232
const onSubmit = async ({ email, password }: { email: string; password: string }) => {
33-
userSend({ type: "SIGN_IN", email, password })
33+
authSend({ type: "SIGN_IN", email, password })
3434
}
3535

36-
if (userState.matches("signedIn")) {
36+
if (authState.matches("signedIn")) {
3737
return <Navigate to={redirectTo} replace />
3838
} else {
3939
return (

site/src/xServices/StateContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useInterpret } from "@xstate/react"
22
import React, { createContext } from "react"
33
import { ActorRefFrom } from "xstate"
4+
import { authMachine } from "./auth/authXService"
45
import { buildInfoMachine } from "./buildInfo/buildInfoXService"
5-
import { userMachine } from "./user/userXService"
66

77
interface XServiceContextType {
88
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
9-
userXService: ActorRefFrom<typeof userMachine>
9+
authXService: ActorRefFrom<typeof authMachine>
1010
}
1111

1212
/**
@@ -24,7 +24,7 @@ export const XServiceProvider: React.FC = ({ children }) => {
2424
<XServiceContext.Provider
2525
value={{
2626
buildInfoXService: useInterpret(buildInfoMachine),
27-
userXService: useInterpret(userMachine),
27+
authXService: useInterpret(authMachine),
2828
}}
2929
>
3030
{children}

site/src/xServices/user/userXService.ts renamed to site/src/xServices/auth/authXService.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import { assign, createMachine } from "xstate"
22
import * as API from "../../api"
33
import * as Types from "../../api/types"
44

5-
export interface UserContext {
5+
export interface AuthContext {
66
getUserError?: Error | unknown
77
authError?: Error | unknown
88
me?: Types.UserResponse
99
}
1010

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 }
1212

13-
export const userMachine =
13+
export const authMachine =
1414
/** @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 */
1515
createMachine(
1616
{
17-
tsTypes: {} as import("./userXService.typegen").Typegen0,
17+
tsTypes: {} as import("./authXService.typegen").Typegen0,
1818
schema: {
19-
context: {} as UserContext,
20-
events: {} as UserEvent,
19+
context: {} as AuthContext,
20+
events: {} as AuthEvent,
2121
services: {} as {
2222
getMe: {
2323
data: Types.UserResponse
@@ -32,13 +32,13 @@ export const userMachine =
3232
getUserError: undefined,
3333
authError: undefined,
3434
},
35-
id: "userState",
35+
id: "authState",
3636
initial: "gettingUser",
3737
states: {
3838
signedOut: {
3939
on: {
4040
SIGN_IN: {
41-
target: "#userState.signingIn",
41+
target: "#authState.signingIn",
4242
},
4343
},
4444
},
@@ -48,14 +48,14 @@ export const userMachine =
4848
id: "signIn",
4949
onDone: [
5050
{
51-
target: "#userState.gettingUser",
51+
target: "#authState.gettingUser",
5252
actions: "clearAuthError",
5353
},
5454
],
5555
onError: [
5656
{
5757
actions: "assignAuthError",
58-
target: "#userState.signedOut",
58+
target: "#authState.signedOut",
5959
},
6060
],
6161
},
@@ -68,13 +68,13 @@ export const userMachine =
6868
onDone: [
6969
{
7070
actions: ["assignMe", "clearGetUserError"],
71-
target: "#userState.signedIn",
71+
target: "#authState.signedIn",
7272
},
7373
],
7474
onError: [
7575
{
7676
actions: "assignGetUserError",
77-
target: "#userState.signedOut",
77+
target: "#authState.signedOut",
7878
},
7979
],
8080
},
@@ -83,7 +83,7 @@ export const userMachine =
8383
signedIn: {
8484
on: {
8585
SIGN_OUT: {
86-
target: "#userState.signingOut",
86+
target: "#authState.signingOut",
8787
},
8888
},
8989
},
@@ -94,13 +94,13 @@ export const userMachine =
9494
onDone: [
9595
{
9696
actions: ["unassignMe", "clearAuthError"],
97-
target: "#userState.signedOut",
97+
target: "#authState.signedOut",
9898
},
9999
],
100100
onError: [
101101
{
102102
actions: "assignAuthError",
103-
target: "#userState.signedIn",
103+
target: "#authState.signedIn",
104104
},
105105
],
106106
},
@@ -120,21 +120,21 @@ export const userMachine =
120120
assignMe: assign({
121121
me: (_, event) => event.data,
122122
}),
123-
unassignMe: assign((context: UserContext) => ({
123+
unassignMe: assign((context: AuthContext) => ({
124124
...context,
125125
me: undefined,
126126
})),
127127
assignGetUserError: assign({
128128
getUserError: (_, event) => event.data,
129129
}),
130-
clearGetUserError: assign((context: UserContext) => ({
130+
clearGetUserError: assign((context: AuthContext) => ({
131131
...context,
132132
getUserError: undefined,
133133
})),
134134
assignAuthError: assign({
135135
authError: (_, event) => event.data,
136136
}),
137-
clearAuthError: assign((context: UserContext) => ({
137+
clearAuthError: assign((context: AuthContext) => ({
138138
...context,
139139
authError: undefined,
140140
})),

0 commit comments

Comments
 (0)