From 72014b66a45a030a04a6dfa7311ddc202b56507d Mon Sep 17 00:00:00 2001 From: Fran McDade Date: Wed, 30 Oct 2024 14:08:51 +1000 Subject: [PATCH] refactor: google sign in and next auth directory structure (#178) --- .../common/types.ts | 11 +++--- .../contants.ts | 10 +++--- .../hooks/useGoogleSignInService.ts | 6 ++-- .../profile/types.ts | 0 .../profile/utils.ts | 2 +- .../provider.tsx | 34 +++++++++---------- .../service/constants.ts | 4 +-- .../service/service.ts | 16 ++++----- .../types.ts | 2 +- .../hooks/useNextAuthService.ts | 8 ++--- .../provider.tsx | 26 +++++++------- .../service/service.ts | 2 +- .../types.ts | 2 +- 13 files changed, 63 insertions(+), 60 deletions(-) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/common/types.ts (74%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/contants.ts (66%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/hooks/useGoogleSignInService.ts (87%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/profile/types.ts (100%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/profile/utils.ts (91%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/provider.tsx (55%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/service/constants.ts (69%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/service/service.ts (79%) rename src/providers/{authentication/googleSignIn => googleSignInAuthentication}/types.ts (70%) rename src/providers/{authentication/nextAuth => nextAuthAuthentication}/hooks/useNextAuthService.ts (67%) rename src/providers/{authentication/nextAuth => nextAuthAuthentication}/provider.tsx (53%) rename src/providers/{authentication/nextAuth => nextAuthAuthentication}/service/service.ts (87%) rename src/providers/{authentication/nextAuth => nextAuthAuthentication}/types.ts (74%) diff --git a/src/providers/authentication/googleSignIn/common/types.ts b/src/providers/googleSignInAuthentication/common/types.ts similarity index 74% rename from src/providers/authentication/googleSignIn/common/types.ts rename to src/providers/googleSignInAuthentication/common/types.ts index 585f1f00..0664383c 100644 --- a/src/providers/authentication/googleSignIn/common/types.ts +++ b/src/providers/googleSignInAuthentication/common/types.ts @@ -2,16 +2,19 @@ import { Dispatch } from "react"; import { AuthenticationAction, AuthenticationContextProps, -} from "../../authentication/types"; +} from "../../authentication/authentication/types"; import { AuthorizationAction, AuthorizationContextProps, -} from "../../authorization/types"; +} from "../../authentication/authorization/types"; import { CredentialsAction, CredentialsContextProps, -} from "../../credentials/types"; -import { TokenAction, TokenContextProps } from "../../token/types"; +} from "../../authentication/credentials/types"; +import { + TokenAction, + TokenContextProps, +} from "../../authentication/token/types"; export interface SessionReducer { authenticationReducer: AuthenticationContextProps; diff --git a/src/providers/authentication/googleSignIn/contants.ts b/src/providers/googleSignInAuthentication/contants.ts similarity index 66% rename from src/providers/authentication/googleSignIn/contants.ts rename to src/providers/googleSignInAuthentication/contants.ts index 43803eba..4c092920 100644 --- a/src/providers/authentication/googleSignIn/contants.ts +++ b/src/providers/googleSignInAuthentication/contants.ts @@ -1,14 +1,14 @@ -import { DEFAULT_AUTH_STATE } from "../auth/constants"; -import { AUTH_STATUS, AuthState } from "../auth/types"; -import { DEFAULT_AUTHENTICATION_STATE } from "../authentication/constants"; +import { DEFAULT_AUTH_STATE } from "../authentication/auth/constants"; +import { AUTH_STATUS, AuthState } from "../authentication/auth/types"; +import { DEFAULT_AUTHENTICATION_STATE } from "../authentication/authentication/constants"; import { AUTHENTICATION_STATUS, AuthenticationState, -} from "../authentication/types"; +} from "../authentication/authentication/types"; import { AUTHORIZATION_STATUS, AuthorizationState, -} from "../authorization/types"; +} from "../authentication/authorization/types"; export const AUTH_STATE: AuthState = { ...DEFAULT_AUTH_STATE, diff --git a/src/providers/authentication/googleSignIn/hooks/useGoogleSignInService.ts b/src/providers/googleSignInAuthentication/hooks/useGoogleSignInService.ts similarity index 87% rename from src/providers/authentication/googleSignIn/hooks/useGoogleSignInService.ts rename to src/providers/googleSignInAuthentication/hooks/useGoogleSignInService.ts index 2123c994..56ec5930 100644 --- a/src/providers/authentication/googleSignIn/hooks/useGoogleSignInService.ts +++ b/src/providers/googleSignInAuthentication/hooks/useGoogleSignInService.ts @@ -1,8 +1,8 @@ import Router from "next/router"; import { useCallback } from "react"; -import { useProviders } from "../../../../hooks/authentication/providers/useProviders"; -import { Service } from "../../auth/types"; -import { ProviderId } from "../../common/types"; +import { useProviders } from "../../../hooks/authentication/providers/useProviders"; +import { Service } from "../../authentication/auth/types"; +import { ProviderId } from "../../authentication/common/types"; import { SessionReducer } from "../common/types"; import { service } from "../service/service"; diff --git a/src/providers/authentication/googleSignIn/profile/types.ts b/src/providers/googleSignInAuthentication/profile/types.ts similarity index 100% rename from src/providers/authentication/googleSignIn/profile/types.ts rename to src/providers/googleSignInAuthentication/profile/types.ts diff --git a/src/providers/authentication/googleSignIn/profile/utils.ts b/src/providers/googleSignInAuthentication/profile/utils.ts similarity index 91% rename from src/providers/authentication/googleSignIn/profile/utils.ts rename to src/providers/googleSignInAuthentication/profile/utils.ts index 75f65736..dda481dc 100644 --- a/src/providers/authentication/googleSignIn/profile/utils.ts +++ b/src/providers/googleSignInAuthentication/profile/utils.ts @@ -1,4 +1,4 @@ -import { UserProfile } from "../../authentication/types"; +import { UserProfile } from "../../authentication/authentication/types"; import { GOOGLE_SIGN_IN_PROVIDER_ID } from "../service/constants"; import { GoogleProfile } from "./types"; diff --git a/src/providers/authentication/googleSignIn/provider.tsx b/src/providers/googleSignInAuthentication/provider.tsx similarity index 55% rename from src/providers/authentication/googleSignIn/provider.tsx rename to src/providers/googleSignInAuthentication/provider.tsx index f6a71b47..26ecfe55 100644 --- a/src/providers/authentication/googleSignIn/provider.tsx +++ b/src/providers/googleSignInAuthentication/provider.tsx @@ -1,31 +1,31 @@ import React from "react"; -import { useAuthReducer } from "../../../hooks/authentication/auth/useAuthReducer"; -import { useAuthenticationReducer } from "../../../hooks/authentication/authentication/useAuthenticationReducer"; -import { useAuthorizationReducer } from "../../../hooks/authentication/authorization/useAuthorizationReducer"; -import { useCredentialsReducer } from "../../../hooks/authentication/credentials/useCredentialsReducer"; -import { useSessionActive } from "../../../hooks/authentication/session/useSessionActive"; -import { useSessionAuth } from "../../../hooks/authentication/session/useSessionAuth"; -import { useSessionCallbackUrl } from "../../../hooks/authentication/session/useSessionCallbackUrl"; -import { useSessionCredentials } from "../../../hooks/authentication/session/useSessionCredentials"; -import { useSessionTimeout } from "../../../hooks/authentication/session/useSessionTimeout"; -import { useTokenReducer } from "../../../hooks/authentication/token/useTokenReducer"; -import { AuthContext } from "../auth/context"; -import { AuthenticationContext } from "../authentication/context"; -import { AuthorizationContext } from "../authorization/context"; -import { CredentialsContext } from "../credentials/context"; +import { useAuthReducer } from "../../hooks/authentication/auth/useAuthReducer"; +import { useAuthenticationReducer } from "../../hooks/authentication/authentication/useAuthenticationReducer"; +import { useAuthorizationReducer } from "../../hooks/authentication/authorization/useAuthorizationReducer"; +import { useCredentialsReducer } from "../../hooks/authentication/credentials/useCredentialsReducer"; +import { useSessionActive } from "../../hooks/authentication/session/useSessionActive"; +import { useSessionAuth } from "../../hooks/authentication/session/useSessionAuth"; +import { useSessionCallbackUrl } from "../../hooks/authentication/session/useSessionCallbackUrl"; +import { useSessionCredentials } from "../../hooks/authentication/session/useSessionCredentials"; +import { useSessionTimeout } from "../../hooks/authentication/session/useSessionTimeout"; +import { useTokenReducer } from "../../hooks/authentication/token/useTokenReducer"; +import { AuthContext } from "../authentication/auth/context"; +import { AuthenticationContext } from "../authentication/authentication/context"; +import { AuthorizationContext } from "../authentication/authorization/context"; +import { CredentialsContext } from "../authentication/credentials/context"; import { AUTH_STATE, AUTHENTICATION_STATE, AUTHORIZATION_STATE, } from "./contants"; import { useGoogleSignInService } from "./hooks/useGoogleSignInService"; -import { GoogleSignInProviderProps } from "./types"; +import { GoogleSignInAuthenticationProviderProps } from "./types"; -export function GoogleSignInProvider({ +export function GoogleSignInAuthenticationProvider({ APIServicesProvider, children, timeout, -}: GoogleSignInProviderProps): JSX.Element { +}: GoogleSignInAuthenticationProviderProps): JSX.Element { const authReducer = useAuthReducer(AUTH_STATE); const authenticationReducer = useAuthenticationReducer(AUTHENTICATION_STATE); const authorizationReducer = useAuthorizationReducer(AUTHORIZATION_STATE); diff --git a/src/providers/authentication/googleSignIn/service/constants.ts b/src/providers/googleSignInAuthentication/service/constants.ts similarity index 69% rename from src/providers/authentication/googleSignIn/service/constants.ts rename to src/providers/googleSignInAuthentication/service/constants.ts index 808e8371..ea875ae6 100644 --- a/src/providers/authentication/googleSignIn/service/constants.ts +++ b/src/providers/googleSignInAuthentication/service/constants.ts @@ -1,5 +1,5 @@ -import { GoogleIcon } from "../../../../components/common/CustomIcon/components/GoogleIcon/googleIcon"; -import { OAuthProvider } from "../../../../config/entities"; +import { GoogleIcon } from "../../../components/common/CustomIcon/components/GoogleIcon/googleIcon"; +import { OAuthProvider } from "../../../config/entities"; import { GoogleProfile } from "../profile/types"; import { mapProfile } from "../profile/utils"; diff --git a/src/providers/authentication/googleSignIn/service/service.ts b/src/providers/googleSignInAuthentication/service/service.ts similarity index 79% rename from src/providers/authentication/googleSignIn/service/service.ts rename to src/providers/googleSignInAuthentication/service/service.ts index 01e7cead..bee777bc 100644 --- a/src/providers/authentication/googleSignIn/service/service.ts +++ b/src/providers/googleSignInAuthentication/service/service.ts @@ -1,21 +1,21 @@ -import { OAuthProvider } from "../../../../config/entities"; +import { OAuthProvider } from "../../../config/entities"; import { requestAuthentication, resetState as resetAuthenticationState, updateAuthentication, -} from "../../authentication/dispatch"; -import { AUTHENTICATION_STATUS } from "../../authentication/types"; -import { fetchProfile } from "../../authentication/utils"; +} from "../../authentication/authentication/dispatch"; +import { AUTHENTICATION_STATUS } from "../../authentication/authentication/types"; +import { fetchProfile } from "../../authentication/authentication/utils"; import { requestAuthorization, resetState as resetAuthorizationState, -} from "../../authorization/dispatch"; -import { resetState as resetCredentialsState } from "../../credentials/dispatch"; -import { getAuthenticationRequestOptions } from "../../terra/hooks/common/utils"; +} from "../../authentication/authorization/dispatch"; +import { resetState as resetCredentialsState } from "../../authentication/credentials/dispatch"; +import { getAuthenticationRequestOptions } from "../../authentication/terra/hooks/common/utils"; import { resetState as resetTokenState, updateToken, -} from "../../token/dispatch"; +} from "../../authentication/token/dispatch"; import { SessionDispatch } from "../common/types"; import { GoogleProfile, TokenSetParameters } from "../profile/types"; diff --git a/src/providers/authentication/googleSignIn/types.ts b/src/providers/googleSignInAuthentication/types.ts similarity index 70% rename from src/providers/authentication/googleSignIn/types.ts rename to src/providers/googleSignInAuthentication/types.ts index eb19aee7..bdf4a594 100644 --- a/src/providers/authentication/googleSignIn/types.ts +++ b/src/providers/googleSignInAuthentication/types.ts @@ -1,6 +1,6 @@ import { ElementType, ReactNode } from "react"; -export interface GoogleSignInProviderProps { +export interface GoogleSignInAuthenticationProviderProps { APIServicesProvider: ElementType; children: ReactNode | ReactNode[]; timeout?: number; diff --git a/src/providers/authentication/nextAuth/hooks/useNextAuthService.ts b/src/providers/nextAuthAuthentication/hooks/useNextAuthService.ts similarity index 67% rename from src/providers/authentication/nextAuth/hooks/useNextAuthService.ts rename to src/providers/nextAuthAuthentication/hooks/useNextAuthService.ts index 3b927659..7c5c2151 100644 --- a/src/providers/authentication/nextAuth/hooks/useNextAuthService.ts +++ b/src/providers/nextAuthAuthentication/hooks/useNextAuthService.ts @@ -1,8 +1,8 @@ import { useCallback } from "react"; -import { transformRoute } from "../../../../hooks/authentication/session/useSessionActive"; -import { useRouteHistory } from "../../../../hooks/useRouteHistory"; -import { Service } from "../../auth/types"; -import { ProviderId } from "../../common/types"; +import { transformRoute } from "../../../hooks/authentication/session/useSessionActive"; +import { useRouteHistory } from "../../../hooks/useRouteHistory"; +import { Service } from "../../authentication/auth/types"; +import { ProviderId } from "../../authentication/common/types"; import { service } from "../service/service"; export const useNextAuthService = (): Service => { diff --git a/src/providers/authentication/nextAuth/provider.tsx b/src/providers/nextAuthAuthentication/provider.tsx similarity index 53% rename from src/providers/authentication/nextAuth/provider.tsx rename to src/providers/nextAuthAuthentication/provider.tsx index 9f659acb..2b1f5def 100644 --- a/src/providers/authentication/nextAuth/provider.tsx +++ b/src/providers/nextAuthAuthentication/provider.tsx @@ -1,23 +1,23 @@ import { SessionProvider } from "next-auth/react"; import React from "react"; -import { SessionController } from "../../../components/Authentication/components/SessionController/SessionController"; -import { useAuthReducer } from "../../../hooks/authentication/auth/useAuthReducer"; -import { useAuthenticationReducer } from "../../../hooks/authentication/authentication/useAuthenticationReducer"; -import { useAuthorizationReducer } from "../../../hooks/authentication/authorization/useAuthorizationReducer"; -import { useSessionAuth } from "../../../hooks/authentication/session/useSessionAuth"; -import { useSessionCallbackUrl } from "../../../hooks/authentication/session/useSessionCallbackUrl"; -import { useSessionTimeout } from "../../../hooks/authentication/session/useSessionTimeout"; -import { AuthContext } from "../auth/context"; -import { AuthenticationContext } from "../authentication/context"; -import { AuthorizationContext } from "../authorization/context"; +import { SessionController } from "../../components/Authentication/components/SessionController/SessionController"; +import { useAuthReducer } from "../../hooks/authentication/auth/useAuthReducer"; +import { useAuthenticationReducer } from "../../hooks/authentication/authentication/useAuthenticationReducer"; +import { useAuthorizationReducer } from "../../hooks/authentication/authorization/useAuthorizationReducer"; +import { useSessionAuth } from "../../hooks/authentication/session/useSessionAuth"; +import { useSessionCallbackUrl } from "../../hooks/authentication/session/useSessionCallbackUrl"; +import { useSessionTimeout } from "../../hooks/authentication/session/useSessionTimeout"; +import { AuthContext } from "../authentication/auth/context"; +import { AuthenticationContext } from "../authentication/authentication/context"; +import { AuthorizationContext } from "../authentication/authorization/context"; import { useNextAuthService } from "./hooks/useNextAuthService"; -import { NextAuthProviderProps } from "./types"; +import { NextAuthAuthenticationProviderProps } from "./types"; -export function NextAuthProvider({ +export function NextAuthAuthenticationProvider({ children, session, timeout, -}: NextAuthProviderProps): JSX.Element { +}: NextAuthAuthenticationProviderProps): JSX.Element { const authReducer = useAuthReducer(); const authenticationReducer = useAuthenticationReducer(); const authorizationReducer = useAuthorizationReducer(); diff --git a/src/providers/authentication/nextAuth/service/service.ts b/src/providers/nextAuthAuthentication/service/service.ts similarity index 87% rename from src/providers/authentication/nextAuth/service/service.ts rename to src/providers/nextAuthAuthentication/service/service.ts index 539c88a1..419cbe66 100644 --- a/src/providers/authentication/nextAuth/service/service.ts +++ b/src/providers/nextAuthAuthentication/service/service.ts @@ -1,5 +1,5 @@ import { signIn, SignInOptions, signOut, SignOutParams } from "next-auth/react"; -import { ProviderId } from "../../common/types"; +import { ProviderId } from "../../authentication/common/types"; export const service = { login: (providerId: ProviderId, options?: SignInOptions): void => { diff --git a/src/providers/authentication/nextAuth/types.ts b/src/providers/nextAuthAuthentication/types.ts similarity index 74% rename from src/providers/authentication/nextAuth/types.ts rename to src/providers/nextAuthAuthentication/types.ts index d8ee2101..0351e7fb 100644 --- a/src/providers/authentication/nextAuth/types.ts +++ b/src/providers/nextAuthAuthentication/types.ts @@ -1,7 +1,7 @@ import { Session } from "next-auth"; import { ReactNode } from "react"; -export interface NextAuthProviderProps { +export interface NextAuthAuthenticationProviderProps { children: ReactNode | ReactNode[]; session?: Session | null; timeout?: number;