chore(site): rename userXService to authXService (#924)

* chore(site): rename userXService to authXService

* Rename contents of xService
This commit is contained in:
Presley Pizzo
2022-04-08 11:42:57 -04:00
committed by GitHub
parent 94ab6f3d8e
commit 0bf9dee7e3
6 changed files with 34 additions and 34 deletions

View File

@ -5,9 +5,9 @@ import { NavbarView } from "./NavbarView"
export const Navbar: React.FC = () => {
const xServices = useContext(XServiceContext)
const [userState, userSend] = useActor(xServices.userXService)
const { me } = userState.context
const onSignOut = () => userSend("SIGN_OUT")
const [authState, authSend] = useActor(xServices.authXService)
const { me } = authState.context
const onSignOut = () => authSend("SIGN_OUT")
return <NavbarView user={me} onSignOut={onSignOut} />
}

View File

@ -11,13 +11,13 @@ export interface RequireAuthProps {
export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
const xServices = useContext(XServiceContext)
const [userState] = useActor(xServices.userXService)
const [authState] = useActor(xServices.authXService)
const location = useLocation()
const redirectTo = embedRedirect(location.pathname)
if (userState.matches("signedOut") || !userState.context.me) {
if (authState.matches("signedOut") || !authState.context.me) {
return <Navigate to={redirectTo} />
} else if (userState.hasTag("loading")) {
} else if (authState.hasTag("loading")) {
return <FullScreenLoader />
} else {
return children

View File

@ -8,8 +8,8 @@ import { XServiceContext } from "../xServices/StateContext"
export const CliAuthenticationPage: React.FC = () => {
const xServices = useContext(XServiceContext)
const [userState] = useActor(xServices.userXService)
const { me } = userState.context
const [authState] = useActor(xServices.authXService)
const { me } = authState.context
const styles = useStyles()

View File

@ -24,16 +24,16 @@ export const SignInPage: React.FC = () => {
const styles = useStyles()
const location = useLocation()
const xServices = useContext(XServiceContext)
const [userState, userSend] = useActor(xServices.userXService)
const isLoading = userState.hasTag("loading")
const [authState, authSend] = useActor(xServices.authXService)
const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search)
const authErrorMessage = userState.context.authError ? (userState.context.authError as Error).message : undefined
const authErrorMessage = authState.context.authError ? (authState.context.authError as Error).message : undefined
const onSubmit = async ({ email, password }: { email: string; password: string }) => {
userSend({ type: "SIGN_IN", email, password })
authSend({ type: "SIGN_IN", email, password })
}
if (userState.matches("signedIn")) {
if (authState.matches("signedIn")) {
return <Navigate to={redirectTo} replace />
} else {
return (

View File

@ -1,12 +1,12 @@
import { useInterpret } from "@xstate/react"
import React, { createContext } from "react"
import { ActorRefFrom } from "xstate"
import { authMachine } from "./auth/authXService"
import { buildInfoMachine } from "./buildInfo/buildInfoXService"
import { userMachine } from "./user/userXService"
interface XServiceContextType {
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
userXService: ActorRefFrom<typeof userMachine>
authXService: ActorRefFrom<typeof authMachine>
}
/**
@ -24,7 +24,7 @@ export const XServiceProvider: React.FC = ({ children }) => {
<XServiceContext.Provider
value={{
buildInfoXService: useInterpret(buildInfoMachine),
userXService: useInterpret(userMachine),
authXService: useInterpret(authMachine),
}}
>
{children}

View File

@ -2,22 +2,22 @@ import { assign, createMachine } from "xstate"
import * as API from "../../api"
import * as Types from "../../api/types"
export interface UserContext {
export interface AuthContext {
getUserError?: Error | unknown
authError?: Error | unknown
me?: Types.UserResponse
}
export type UserEvent = { type: "SIGN_OUT" } | { type: "SIGN_IN"; email: string; password: string }
export type AuthEvent = { type: "SIGN_OUT" } | { type: "SIGN_IN"; email: string; password: string }
export const userMachine =
export const authMachine =
/** @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 */
createMachine(
{
tsTypes: {} as import("./userXService.typegen").Typegen0,
tsTypes: {} as import("./authXService.typegen").Typegen0,
schema: {
context: {} as UserContext,
events: {} as UserEvent,
context: {} as AuthContext,
events: {} as AuthEvent,
services: {} as {
getMe: {
data: Types.UserResponse
@ -32,13 +32,13 @@ export const userMachine =
getUserError: undefined,
authError: undefined,
},
id: "userState",
id: "authState",
initial: "gettingUser",
states: {
signedOut: {
on: {
SIGN_IN: {
target: "#userState.signingIn",
target: "#authState.signingIn",
},
},
},
@ -48,14 +48,14 @@ export const userMachine =
id: "signIn",
onDone: [
{
target: "#userState.gettingUser",
target: "#authState.gettingUser",
actions: "clearAuthError",
},
],
onError: [
{
actions: "assignAuthError",
target: "#userState.signedOut",
target: "#authState.signedOut",
},
],
},
@ -68,13 +68,13 @@ export const userMachine =
onDone: [
{
actions: ["assignMe", "clearGetUserError"],
target: "#userState.signedIn",
target: "#authState.signedIn",
},
],
onError: [
{
actions: "assignGetUserError",
target: "#userState.signedOut",
target: "#authState.signedOut",
},
],
},
@ -83,7 +83,7 @@ export const userMachine =
signedIn: {
on: {
SIGN_OUT: {
target: "#userState.signingOut",
target: "#authState.signingOut",
},
},
},
@ -94,13 +94,13 @@ export const userMachine =
onDone: [
{
actions: ["unassignMe", "clearAuthError"],
target: "#userState.signedOut",
target: "#authState.signedOut",
},
],
onError: [
{
actions: "assignAuthError",
target: "#userState.signedIn",
target: "#authState.signedIn",
},
],
},
@ -120,21 +120,21 @@ export const userMachine =
assignMe: assign({
me: (_, event) => event.data,
}),
unassignMe: assign((context: UserContext) => ({
unassignMe: assign((context: AuthContext) => ({
...context,
me: undefined,
})),
assignGetUserError: assign({
getUserError: (_, event) => event.data,
}),
clearGetUserError: assign((context: UserContext) => ({
clearGetUserError: assign((context: AuthContext) => ({
...context,
getUserError: undefined,
})),
assignAuthError: assign({
authError: (_, event) => event.data,
}),
clearAuthError: assign((context: UserContext) => ({
clearAuthError: assign((context: AuthContext) => ({
...context,
authError: undefined,
})),