Skip to content

chore(site): rename userXService to authXService #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions site/src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
}
6 changes: 3 additions & 3 deletions site/src/components/Page/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/cli-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions site/src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions site/src/xServices/StateContext.tsx
Original file line number Diff line number Diff line change
@@ -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>
}

/**
Expand All @@ -24,7 +24,7 @@ export const XServiceProvider: React.FC = ({ children }) => {
<XServiceContext.Provider
value={{
buildInfoXService: useInterpret(buildInfoMachine),
userXService: useInterpret(userMachine),
authXService: useInterpret(authMachine),
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
],
},
Expand All @@ -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",
},
],
},
Expand All @@ -83,7 +83,7 @@ export const userMachine =
signedIn: {
on: {
SIGN_OUT: {
target: "#userState.signingOut",
target: "#authState.signingOut",
},
},
},
Expand All @@ -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",
},
],
},
Expand All @@ -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,
})),
Expand Down