From e1d3c19458239dbea3c102d46e868f8e4add57b2 Mon Sep 17 00:00:00 2001 From: shreeyash07 Date: Wed, 9 Oct 2024 10:50:17 +0545 Subject: [PATCH] Remove HID related login logics --- app/Base/configs/env.ts | 5 -- app/Base/configs/hid.ts | 12 ---- app/views/Login/LoginForm/index.tsx | 104 +--------------------------- 3 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 app/Base/configs/hid.ts diff --git a/app/Base/configs/env.ts b/app/Base/configs/env.ts index 7881b2eca5..4c619b4b07 100644 --- a/app/Base/configs/env.ts +++ b/app/Base/configs/env.ts @@ -36,11 +36,6 @@ export const sentryAppDsn = process.env.REACT_APP_SENTRY_DSN; export const sentryTraceSampleRate = Number(process.env.REACT_APP_SENTRY_TRACES_SAMPLE_RATE) || 0.2; export const sentryNormalizeDepth = Number(process.env.REACT_APP_SENTRY_NORMALIZE_DEPTH) || 5; -// Humanitarian ID -export const hidClientId = process.env.REACT_APP_HID_CLIENT_ID || 'deep-local'; -export const hidRedirectUrl = process.env.REACT_APP_HID_CLIENT_REDIRECT_URL || 'http://localhost:3000/login/'; -export const hidAuthUrl = process.env.REACT_APP_HID_AUTH_URI || 'https://api2.dev.humanitarian.id'; - // Hcaptcha export const hCaptchaKey = process.env.REACT_APP_HCATPCHA_SITEKEY || '10000000-ffff-ffff-ffff-000000000001'; diff --git a/app/Base/configs/hid.ts b/app/Base/configs/hid.ts deleted file mode 100644 index 70732ea228..0000000000 --- a/app/Base/configs/hid.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { - hidClientId, - hidRedirectUrl, - hidAuthUrl, -} from './env'; - -const responseType = 'token'; -const scope = 'profile'; -const state = '12345'; -// NOTE: HID doesn't seem to decode the params, so don't use `p` for now -// eslint-disable-next-line import/prefer-default-export -export const hidUrl = `${hidAuthUrl}/oauth/authorize?response_type=${responseType}&client_id=${hidClientId}&scope=${scope}&state=${state}&redirect_uri=${hidRedirectUrl}`; diff --git a/app/views/Login/LoginForm/index.tsx b/app/views/Login/LoginForm/index.tsx index 6d02f5bd43..3276fbf0bd 100644 --- a/app/views/Login/LoginForm/index.tsx +++ b/app/views/Login/LoginForm/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState, useRef, useMemo, useCallback } from 'react'; +import React, { useContext, useState, useRef, useMemo, useCallback } from 'react'; import { _cs } from '@togglecorp/fujs'; import { useMutation, gql } from '@apollo/client'; import { IoChevronForwardSharp } from 'react-icons/io5'; @@ -11,7 +11,6 @@ import { Container, PasswordInput, PendingMessage, - ButtonLikeLink, } from '@the-deep/deep-ui'; import { internal, @@ -29,11 +28,9 @@ import Captcha from '@hcaptcha/react-hcaptcha'; import SmartLink from '#base/components/SmartLink'; import SmartButtonLikeLink from '#base/components/SmartButtonLikeLink'; -import { parseUrlParams } from '#utils/common'; import { UserContext } from '#base/context/UserContext'; import { ProjectContext } from '#base/context/ProjectContext'; import HCaptcha from '#components/HCaptcha'; -import { hidUrl } from '#base/configs/hid'; import NonFieldError from '#components/NonFieldError'; import { transformToFormError, ObjectError } from '#base/utils/errorTransform'; import routes from '#base/configs/routes'; @@ -43,23 +40,11 @@ import _ts from '#ts'; import { LoginMutation, LoginMutationVariables, - LoginWithHidMutation, - LoginWithHidMutationVariables, } from '#generated/types'; import { hCaptchaKey } from '#base/configs/hCaptcha'; import styles from './styles.css'; -interface HidQuery { - - access_token: string; - - expires_in: number; - state: number; - - token_type: string; -} - interface LoginFields { // NOTE: Email must be sent as email email: string; @@ -90,28 +75,6 @@ const LOGIN = gql` } `; -const LOGIN_WITH_HID = gql` - ${LAST_ACTIVE_PROJECT_FRAGMENT} - mutation LoginWithHid($input: HIDLoginInputType!) { - loginWithHid(data: $input) { - result { - email - id - displayName - displayPictureUrl - accessibleFeatures { - key - } - lastActiveProject { - ...LastActiveProjectResponse - } - } - errors - ok - } - } -`; - type FormType = Partial; type FormSchema = ObjectSchema; type FormSchemaFields = ReturnType; @@ -206,62 +169,6 @@ function LoginForm(props: Props) { }, ); - const [ - loginWithHid, - { loading: hidLoginPending }, - ] = useMutation( - LOGIN_WITH_HID, - { - onCompleted: (response) => { - const { loginWithHid: loginRes } = response; - if (!loginRes) { - return; - } - const { - errors, - result, - ok, - } = loginRes; - - if (errors) { - const formError = transformToFormError(removeNull(errors) as ObjectError[]); - setError(formError); - } else if (ok) { - const safeUser = removeNull(result); - setUser(safeUser); - setProject(safeUser.lastActiveProject); - } - }, - onError: (errors) => { - setError({ - [internal]: errors.message, - }); - }, - }, - ); - - useEffect(() => { - // Get params from the current url - // NOTE: hid provides query as hash - - const query = parseUrlParams(window.location?.hash?.replace('#', '')) as { access_token?: string }; - // Login User with HID access_token - if (query.access_token) { - const hidQuery = query as HidQuery; - const params = { - accessToken: hidQuery.access_token, - expiresIn: hidQuery.expires_in, - state: hidQuery.state, - tokenType: hidQuery.token_type, - }; - loginWithHid({ - variables: { - input: params, - }, - }); - } - }, [loginWithHid]); - const handleSubmit = useCallback((finalValue: FormType) => { elementRef.current?.resetCaptcha(); login({ @@ -271,7 +178,7 @@ function LoginForm(props: Props) { }); }, [login]); - const pending = hidLoginPending || loginPending; + const pending = loginPending; return (
{_ts('explore.login', 'loginButtonLabel')} - - {_ts('explore.login', 'loginWithHid')} -