feat(client/auth/google): disable google login/registration if GOOGLE_CLIENT_ID is not in ENV

fix #724
This commit is contained in:
Amruth Pillai
2022-03-17 12:17:41 +01:00
parent 39fa6da5dd
commit 7f0ee40af4
3 changed files with 31 additions and 25 deletions

View File

@ -1,6 +1,6 @@
# App
TZ=UTC
SECRET_KEY=change-me
SECRET_KEY=
# URLs
PUBLIC_URL=http://<SERVER-IP>
@ -15,13 +15,13 @@ POSTGRES_DATABASE=postgres
POSTGRES_SSL_CERT=
# Auth
JWT_SECRET=change-me
JWT_SECRET=
JWT_EXPIRY_TIME=604800
# Google
PUBLIC_GOOGLE_CLIENT_ID=change-me
GOOGLE_CLIENT_SECRET=change-me
GOOGLE_API_KEY=change-me
PUBLIC_GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_API_KEY=
# SendGrid (Optional)
SENDGRID_API_KEY=

View File

@ -3,6 +3,7 @@ import { joiResolver } from '@hookform/resolvers/joi';
import { Google, Login, Visibility, VisibilityOff } from '@mui/icons-material';
import { Button, IconButton, InputAdornment, TextField } from '@mui/material';
import Joi from 'joi';
import { isEmpty } from 'lodash';
import { Trans, useTranslation } from 'next-i18next';
import { useMemo, useState } from 'react';
import { GoogleLoginResponse, GoogleLoginResponseOffline, useGoogleLogin } from 'react-google-login';
@ -115,15 +116,17 @@ const LoginModal: React.FC = () => {
handleClose={handleClose}
footerChildren={
<div className="flex gap-4">
<Button
type="submit"
variant="outlined"
disabled={isLoading}
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.login.actions.google')}
</Button>
{!isEmpty(env('GOOGLE_CLIENT_ID')) && (
<Button
type="submit"
variant="outlined"
disabled={isLoading}
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.login.actions.google')}
</Button>
)}
<Button type="submit" onClick={handleSubmit(onSubmit)} disabled={isLoading}>
{t('modals.auth.login.actions.login')}

View File

@ -3,6 +3,7 @@ import { joiResolver } from '@hookform/resolvers/joi';
import { Google, HowToReg } from '@mui/icons-material';
import { Button, TextField } from '@mui/material';
import Joi from 'joi';
import { isEmpty } from 'lodash';
import { Trans, useTranslation } from 'next-i18next';
import { GoogleLoginResponse, GoogleLoginResponseOffline, useGoogleLogin } from 'react-google-login';
import { Controller, useForm } from 'react-hook-form';
@ -97,21 +98,23 @@ const RegisterModal: React.FC = () => {
heading={t('modals.auth.register.heading')}
handleClose={handleClose}
footerChildren={
<>
<Button
type="submit"
variant="outlined"
disabled={isLoading}
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.register.actions.google')}
</Button>
<div className="flex gap-4">
{!isEmpty(env('GOOGLE_CLIENT_ID')) && (
<Button
type="submit"
variant="outlined"
disabled={isLoading}
startIcon={<Google />}
onClick={handleLoginWithGoogle}
>
{t('modals.auth.register.actions.google')}
</Button>
)}
<Button type="submit" onClick={handleSubmit(onSubmit)} disabled={isLoading}>
{t('modals.auth.register.actions.register')}
</Button>
</>
</div>
}
>
<p>{t('modals.auth.register.body')}</p>