-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0f6c2f
commit f6ef737
Showing
16 changed files
with
191 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
NEXT_PUBLIC_API_URL=https://nestjs-boilerplate-test.herokuapp.com/api | ||
|
||
NEXT_PUBLIC_IS_GOOGLE_AUTH_ENABLED=true | ||
NEXT_PUBLIC_GOOGLE_CLIENT_ID=778828327699-3hu034kj1u76k4o5qla8221ovtbgl2g0.apps.googleusercontent.com |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Box from "@mui/material/Box"; | ||
import CircularProgress from "@mui/material/CircularProgress"; | ||
import Modal from "@mui/material/Modal"; | ||
|
||
type FullPageLoaderType = { | ||
isLoading: boolean; | ||
}; | ||
|
||
export function FullPageLoader({ isLoading }: FullPageLoaderType) { | ||
return ( | ||
<Modal open={isLoading}> | ||
<Box | ||
sx={{ | ||
position: "absolute", | ||
top: "50%", | ||
left: "50%", | ||
transform: "translate(-50%, -50%)", | ||
outline: "none", | ||
}} | ||
> | ||
<CircularProgress /> | ||
</Box> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { FileEntity } from "./file-entity"; | ||
|
||
export enum UserProviderEnum { | ||
EMAIL = "email", | ||
GOOGLE = "google", | ||
} | ||
|
||
export type User = { | ||
id: number; | ||
email: string; | ||
firstName?: string; | ||
lastName?: string; | ||
photo?: FileEntity; | ||
provider?: UserProviderEnum; | ||
socialId?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,6 @@ | |
} | ||
} | ||
} | ||
} | ||
}, | ||
"or": "OR" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,6 @@ | |
} | ||
} | ||
} | ||
} | ||
}, | ||
"or": "OR" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use client"; | ||
|
||
import { GoogleOAuthProvider as GoogleProvider } from "@react-oauth/google"; | ||
import { isGoogleAuthEnabled, googleClientId } from "./google-config"; | ||
|
||
function GoogleOAuthProvider({ children }: { children: React.ReactNode }) { | ||
return isGoogleAuthEnabled && googleClientId ? ( | ||
<GoogleProvider clientId={googleClientId}>{children}</GoogleProvider> | ||
) : ( | ||
children | ||
); | ||
} | ||
|
||
export default GoogleOAuthProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client"; | ||
|
||
import { useAuthGoogleLoginService } from "@/services/api/services/auth"; | ||
import HTTP_CODES_ENUM from "@/services/api/types/http-codes"; | ||
import useAuthActions from "@/services/auth/use-auth-actions"; | ||
import useAuthTokens from "@/services/auth/use-auth-tokens"; | ||
import { CredentialResponse, GoogleLogin } from "@react-oauth/google"; | ||
import { useState } from "react"; | ||
import { FullPageLoader } from "@/components/full-page-loader"; | ||
import useLanguage from "@/services/i18n/use-language"; | ||
|
||
export default function GoogleSignIn() { | ||
const { setUser } = useAuthActions(); | ||
const { setTokensInfo } = useAuthTokens(); | ||
const authGoogleLoginService = useAuthGoogleLoginService(); | ||
const language = useLanguage(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const onSuccess = async (tokenResponse: CredentialResponse) => { | ||
if (!tokenResponse.credential) return; | ||
|
||
setIsLoading(true); | ||
|
||
const { status, data } = await authGoogleLoginService({ | ||
idToken: tokenResponse.credential, | ||
}); | ||
|
||
if (status === HTTP_CODES_ENUM.OK) { | ||
setTokensInfo({ | ||
token: data.token, | ||
refreshToken: data.refreshToken, | ||
tokenExpires: data.tokenExpires, | ||
}); | ||
setUser(data.user); | ||
} | ||
setIsLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<GoogleLogin onSuccess={onSuccess} locale={language} /> | ||
<FullPageLoader isLoading={isLoading} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isGoogleAuthEnabled = | ||
process.env.NEXT_PUBLIC_IS_GOOGLE_AUTH_ENABLED === "true"; | ||
export const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use client"; | ||
|
||
import GoogleSignIn from "./google/google-auth"; | ||
import { isGoogleAuthEnabled } from "./google/google-config"; | ||
|
||
export default function SocialAuth() { | ||
return <>{isGoogleAuthEnabled && <GoogleSignIn />}</>; | ||
} |