added signup v3 endpoints and developed initial new signup flow

This commit is contained in:
Sheen Capadngan
2023-05-04 01:32:40 +08:00
parent f703ee29e5
commit 1172726e74
15 changed files with 243 additions and 34 deletions
@@ -12,7 +12,6 @@ import { getTranslatedStaticProps } from '@app/components/utilities/withTranslat
import SecurityClient from '../utilities/SecurityClient';
export default function PasswordInputStep({
userId,
email,
password,
setPassword,
@@ -20,7 +19,6 @@ export default function PasswordInputStep({
setStep
}: {
email: string;
userId: string;
password: string;
setPassword: (password: string) => void;
setProviderAuthToken: (value: string) => void;
@@ -34,13 +32,8 @@ export default function PasswordInputStep({
const handleLogin = async () => {
try {
if (!userId || !password) {
return;
}
setIsLoading(true);
const isLoginSuccessful = await attemptLogin({
userId,
email,
password
});
@@ -32,6 +32,7 @@ interface UserInfoStepProps {
setFirstName: (value: string) => void;
lastName: string;
setLastName: (value: string) => void;
providerAuthToken?: string;
}
/**
@@ -55,7 +56,8 @@ export default function UserInfoStep({
firstName,
setFirstName,
lastName,
setLastName
setLastName,
providerAuthToken,
}: UserInfoStepProps): JSX.Element {
const [firstNameError, setFirstNameError] = useState(false);
const [lastNameError, setLastNameError] = useState(false);
@@ -118,11 +120,11 @@ export default function UserInfoStep({
parallelism: 1,
hashLen: 32
});
if (!derivedKey) throw new Error('Failed to derive key from password');
const key = crypto.randomBytes(32);
// create encrypted private key by encrypting the private
// key with the symmetric key [key]
const {
@@ -133,7 +135,7 @@ export default function UserInfoStep({
text: privateKey,
secret: key
});
// create the protected key by encrypting the symmetric key
// [key] with the derived key
const {
@@ -144,7 +146,7 @@ export default function UserInfoStep({
text: key.toString('hex'),
secret: Buffer.from(derivedKey.hash)
});
const response = await completeAccountInformationSignup({
email,
firstName,
@@ -156,11 +158,12 @@ export default function UserInfoStep({
encryptedPrivateKey,
encryptedPrivateKeyIV,
encryptedPrivateKeyTag,
providerAuthToken,
salt: result.salt,
verifier: result.verifier,
organizationName: `${firstName}'s organization`
organizationName: `${firstName}'s organization`,
});
// unset signup JWT token and set JWT token
SecurityClient.setSignupToken('');
SecurityClient.setToken(response.token);
@@ -29,20 +29,17 @@ const attemptLogin = async (
{
email,
password,
userId,
}: {
email: string;
userId?: string;
password: string;
}
): Promise<IsLoginSuccessful> => {
const username = userId ?? email;
const telemetry = new Telemetry().getInstance();
return new Promise((resolve, reject) => {
client.init(
{
username,
username: email,
password
},
async () => {
@@ -51,7 +48,6 @@ const attemptLogin = async (
const { serverPublicKey, salt } = await login1({
email,
clientPublicKey,
userId,
});
client.setSalt(salt);
@@ -72,7 +68,6 @@ const attemptLogin = async (
} = await login2(
{
email,
userId,
clientProof,
}
);