Skip to content

Commit

Permalink
refactor: google sign in and next auth directory structure (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran McDade authored and Fran McDade committed Oct 30, 2024
1 parent dd975b7 commit 72014b6
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ElementType, ReactNode } from "react";

export interface GoogleSignInProviderProps {
export interface GoogleSignInAuthenticationProviderProps {
APIServicesProvider: ElementType;
children: ReactNode | ReactNode[];
timeout?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 72014b6

Please sign in to comment.