Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/Base/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
12 changes: 0 additions & 12 deletions app/Base/configs/hid.ts

This file was deleted.

104 changes: 2 additions & 102 deletions app/views/Login/LoginForm/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,7 +11,6 @@ import {
Container,
PasswordInput,
PendingMessage,
ButtonLikeLink,
} from '@the-deep/deep-ui';
import {
internal,
Expand All @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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<LoginFields>;
type FormSchema = ObjectSchema<FormType>;
type FormSchemaFields = ReturnType<FormSchema['fields']>;
Expand Down Expand Up @@ -206,62 +169,6 @@ function LoginForm(props: Props) {
},
);

const [
loginWithHid,
{ loading: hidLoginPending },
] = useMutation<LoginWithHidMutation, LoginWithHidMutationVariables>(
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({
Expand All @@ -271,7 +178,7 @@ function LoginForm(props: Props) {
});
}, [login]);

const pending = hidLoginPending || loginPending;
const pending = loginPending;

return (
<form
Expand Down Expand Up @@ -343,13 +250,6 @@ function LoginForm(props: Props) {
>
{_ts('explore.login', 'loginButtonLabel')}
</Button>
<ButtonLikeLink
disabled={pristine || pending}
variant="secondary"
to={hidUrl}
>
{_ts('explore.login', 'loginWithHid')}
</ButtonLikeLink>
</Container>
<div className={styles.rightContent}>
<Kraken
Expand Down