From 0bf9dee7e398832f65f7b3eb5f61d0d088f12cba Mon Sep 17 00:00:00 2001 From: Presley Pizzo <1290996+presleyp@users.noreply.github.com> Date: Fri, 8 Apr 2022 11:42:57 -0400 Subject: [PATCH] chore(site): rename userXService to authXService (#924) * chore(site): rename userXService to authXService * Rename contents of xService --- site/src/components/Navbar/index.tsx | 6 ++-- site/src/components/Page/RequireAuth.tsx | 6 ++-- site/src/pages/cli-auth.tsx | 4 +-- site/src/pages/login.tsx | 10 +++--- site/src/xServices/StateContext.tsx | 6 ++-- .../userXService.ts => auth/authXService.ts} | 36 +++++++++---------- 6 files changed, 34 insertions(+), 34 deletions(-) rename site/src/xServices/{user/userXService.ts => auth/authXService.ts} (81%) diff --git a/site/src/components/Navbar/index.tsx b/site/src/components/Navbar/index.tsx index dd4004e588..48b4e9ecd6 100644 --- a/site/src/components/Navbar/index.tsx +++ b/site/src/components/Navbar/index.tsx @@ -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 } diff --git a/site/src/components/Page/RequireAuth.tsx b/site/src/components/Page/RequireAuth.tsx index 16fc5c835f..011d958146 100644 --- a/site/src/components/Page/RequireAuth.tsx +++ b/site/src/components/Page/RequireAuth.tsx @@ -11,13 +11,13 @@ export interface RequireAuthProps { export const RequireAuth: React.FC = ({ 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 - } else if (userState.hasTag("loading")) { + } else if (authState.hasTag("loading")) { return } else { return children diff --git a/site/src/pages/cli-auth.tsx b/site/src/pages/cli-auth.tsx index 3887bc7249..034d8d60ff 100644 --- a/site/src/pages/cli-auth.tsx +++ b/site/src/pages/cli-auth.tsx @@ -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() diff --git a/site/src/pages/login.tsx b/site/src/pages/login.tsx index f917471c16..ec475f8702 100644 --- a/site/src/pages/login.tsx +++ b/site/src/pages/login.tsx @@ -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 } else { return ( diff --git a/site/src/xServices/StateContext.tsx b/site/src/xServices/StateContext.tsx index d043f463c2..211f1991bb 100644 --- a/site/src/xServices/StateContext.tsx +++ b/site/src/xServices/StateContext.tsx @@ -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 - userXService: ActorRefFrom + authXService: ActorRefFrom } /** @@ -24,7 +24,7 @@ export const XServiceProvider: React.FC = ({ children }) => { {children} diff --git a/site/src/xServices/user/userXService.ts b/site/src/xServices/auth/authXService.ts similarity index 81% rename from site/src/xServices/user/userXService.ts rename to site/src/xServices/auth/authXService.ts index 98d32f09c7..ea74bea36d 100644 --- a/site/src/xServices/user/userXService.ts +++ b/site/src/xServices/auth/authXService.ts @@ -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, })),