From 593e9c7c2ce8b626796cbab0137bf4ec79f29645 Mon Sep 17 00:00:00 2001 From: mehrzadghdev Date: Mon, 22 Sep 2025 23:07:52 +0330 Subject: [PATCH] feat: google authentication added --- .env | 2 +- index.html | 1 + .../GoogleAuthentication.tsx | 9 +- .../GoogleAuthenticationV2.tsx | 112 ++++++++++++++++++ .../AuthenticationSteps/LoginRegiserForm.tsx | 4 +- 5 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 src/features/authentication/components/AuthenticationSteps/GoogleAuthenticationV2.tsx diff --git a/.env b/.env index c7fa122..24dc277 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -VITE_GOOGLE_CLIENT_ID=https://272098283932-bft2gvlgjn8edopg0lnqjq1i9ekdmipt.apps.googleusercontent.com +VITE_GOOGLE_CLIENT_ID=272098283932-bft2gvlgjn8edopg0lnqjq1i9ekdmipt.apps.googleusercontent.com VITE_DEFUALT_AUTH_RETURN_URL=/setting/profile VITE_APP_URL=https://accounts.business-harmony.com VITE_API_URL=https://accounts.business-harmony.com/api diff --git a/index.html b/index.html index 6255f17..5385387 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@ } catch (e) {} })(); + diff --git a/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx b/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx index 275a430..a5bfafa 100644 --- a/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx +++ b/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx @@ -25,6 +25,9 @@ export interface GoogleAuthenticationProps { ) => void; } +/** + * @deprecated use V2 instead + */ export const GoogleAuthentication = ({ disabled, authFactory, @@ -44,11 +47,8 @@ export const GoogleAuthentication = ({ document.body.appendChild(script); script.onload = () => { - clientRef.current = google.accounts.oauth2.initCodeClient({ + clientRef.current = google.accounts.id.initialize({ client_id: import.meta.env.VITE_GOOGLE_CLIENT_ID, - scope: 'openid email profile', - ux_mode: 'popup', - response_type: 'code', callback: async (resp: GoogleCodeClientResponse) => { const apiRequest: LoginOrSignUpWithGoogleRequest = { idToken: resp.id_token, @@ -88,6 +88,7 @@ export const GoogleAuthentication = ({ return ( + + ); +}; diff --git a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx index e1fd6e8..6257172 100644 --- a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx +++ b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx @@ -9,11 +9,11 @@ import { CountryCodeSelector } from '../CountryCodeSelector'; import type { LoginResult, UserStatus } from '../../types/userTypes'; import { getUserStatusByPhoneNumberOrEmail } from '../../api/authorizationAPI'; import type { CountryCode } from '@/types/commonTypes'; -import { GoogleAuthentication } from './GoogleAuthentication'; import { isPhoneNumber } from '@/utils/regexes/isValidPhoneNumber'; import { useToast } from '@rkheftan/harmony-ui'; import { useApi } from '@/hooks/useApi'; import type { GenerateTokenResponse } from '../../api/identityAPI'; +import { GoogleAuthenticationV2 } from './GoogleAuthenticationV2'; export interface LoginRegisterFormProps { loginRegisterValue: string; @@ -173,7 +173,7 @@ export function LoginRegisterForm({ {t('loginForm.submitButton')} -