Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save signup fields #10768

Merged
merged 4 commits into from
Mar 3, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
signInWithEmailAndPassword,
sendPasswordResetEmail,
confirmPasswordReset,
updateProfile,
applyActionCode,
sendEmailVerification,
EmailAuthProvider,
Expand Down Expand Up @@ -89,6 +90,13 @@ export class GoogleAuthService implements AuthService {
);
}

async updateProfile(displayName: string): Promise<void> {
jamakase marked this conversation as resolved.
Show resolved Hide resolved
if (this.auth.currentUser === null) {
throw new Error("Not able to update profile for not loggedIn user!");
}
return updateProfile(this.auth.currentUser, { displayName });
}

async reauthenticate(
email: string,
password: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class UserService extends AirbyteRequestService {
authProvider: string;
email: string;
name: string;
companyName: string;
news: boolean;
invitedWorkspaceId?: string;
status?: "invited";
}): Promise<User> {
Expand Down
70 changes: 59 additions & 11 deletions airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext, useEffect, useMemo } from "react";
import { useQueryClient } from "react-query";
import { useResetter } from "rest-hooks";
import { User as FbUser } from "firebase/auth";

import { GoogleAuthService } from "packages/cloud/lib/auth/GoogleAuthService";
import useTypesafeReducer from "hooks/useTypesafeReducer";
Expand Down Expand Up @@ -35,7 +36,10 @@ export type AuthLogin = (values: {
export type AuthSignUp = (form: {
email: string;
password: string;
}) => Promise<User | null>;
companyName: string;
name: string;
news: boolean;
}) => Promise<void>;

export type AuthChangeEmail = (
email: string,
Expand Down Expand Up @@ -64,6 +68,46 @@ type AuthContextApi = {

export const AuthContext = React.createContext<AuthContextApi | null>(null);

const getTempSignUpStorageKey = (currentUser: FbUser): string =>
`${currentUser.uid}/temp-signup-data`;

const TempSignUpValuesProvider = {
get: (
currentUser: FbUser
): {
companyName: string;
name: string;
news: boolean;
} => {
try {
const key = getTempSignUpStorageKey(currentUser);

const storedValue = localStorage.getItem(key);

if (storedValue) {
return JSON.parse(storedValue);
}
} catch (err) {
// passthrough and return default values
}

return {
companyName: "",
name: currentUser.email ?? "",
news: false,
};
},
save: (
currentUser: FbUser,
v: { companyName: string; name: string; news: boolean }
) => {
localStorage.setItem(
getTempSignUpStorageKey(currentUser),
JSON.stringify(v)
);
},
};

export const AuthenticationProvider: React.FC = ({ children }) => {
const [
state,
Expand All @@ -89,11 +133,14 @@ export const AuthenticationProvider: React.FC = ({ children }) => {
);
} catch (err) {
if (currentUser.email) {
const encodedData = TempSignUpValuesProvider.get(currentUser);
user = await userService.create({
authProvider: AuthProviders.GoogleIdentityPlatform,
authUserId: currentUser.uid,
email: currentUser.email,
name: currentUser.email,
name: encodedData.name,
companyName: encodedData.companyName,
news: encodedData.news,
});
}
}
Expand Down Expand Up @@ -158,17 +205,18 @@ export const AuthenticationProvider: React.FC = ({ children }) => {
async signUp(form: {
email: string;
password: string;
}): Promise<User | null> {
await authService.signUp(form.email, form.password);
// const user = await userService.create({
// authProvider: AuthProviders.GoogleIdentityPlatform,
// authUserId: fbUser.user!.uid,
// email: form.email,
// name: form.email,
// });
companyName: string;
name: string;
news: boolean;
}): Promise<void> {
const creds = await authService.signUp(form.email, form.password);
TempSignUpValuesProvider.save(creds.user, {
companyName: form.companyName,
name: form.name,
news: form.news,
});

await authService.sendEmailVerifiedLink();
return null;
},
user: state.currentUser,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import SpecialBlock from "./components/SpecialBlock";

type FormValues = {
name: string;
company: string;
companyName: string;
email: string;
password: string;
subscribe: boolean;
news: boolean;
security: boolean;
};

Expand All @@ -38,7 +38,7 @@ const SignupPageValidationSchema = yup.object().shape({
.min(6, "signup.password.minLength")
.required("form.empty.error"),
name: yup.string().required("form.empty.error"),
company: yup.string().required("form.empty.error"),
companyName: yup.string().required("form.empty.error"),
security: yup.boolean().oneOf([true], "form.empty.error"),
});

Expand All @@ -58,10 +58,10 @@ const SignupPage: React.FC = () => {
<Formik<FormValues>
initialValues={{
name: "",
company: "",
companyName: "",
email: "",
password: "",
subscribe: true,
news: true,
security: false,
}}
validationSchema={SignupPageValidationSchema}
Expand Down Expand Up @@ -98,7 +98,7 @@ const SignupPage: React.FC = () => {
/>
)}
</Field>
<Field name="company">
<Field name="companyName">
{({ field, meta }: FieldProps<string>) => (
<LabeledInput
{...field}
Expand Down Expand Up @@ -158,7 +158,7 @@ const SignupPage: React.FC = () => {
</Field>
</FieldItem>
<FieldItem>
<Field name="subscribe">
<Field name="news">
{({ field, meta }: FieldProps<string>) => (
<MarginBlock>
<CheckBoxControl
Expand Down