+ Didn't receive a code? Please check your spam folder.
+
+
);
};
diff --git a/app/pages/HomePage/HomePage.tsx b/app/pages/HomePage/HomePage.tsx
index c68544441..2a55b8c81 100644
--- a/app/pages/HomePage/HomePage.tsx
+++ b/app/pages/HomePage/HomePage.tsx
@@ -86,11 +86,11 @@ export const HomePage = () => {
});
useEffect(() => {
- // Todo: This effect should be moved to the case worker UI homepage when that page is created
+ // TODO: This effect should be moved to the case worker UI homepage when that page is created
const { hash } = window.location;
if (!hash || !hash.includes("access_token")) return;
- AuthService.persistUser(
+ AuthService.initializeUserSession(
window.location.hash,
authClient as WebAuth,
setAuthState
diff --git a/app/utils/AuthService.ts b/app/utils/AuthService.ts
index 91550ab60..9c10c168a 100644
--- a/app/utils/AuthService.ts
+++ b/app/utils/AuthService.ts
@@ -5,7 +5,7 @@ import type { AuthState } from "components/AppProvider";
/*
This class provides a set of methods that serve as an interface between our application
- and the Auth0 servers where the user's state and data is stored.
+ and the Auth0 servers where the user's auth state and data is stored.
*/
export default class AuthService {
@@ -18,7 +18,11 @@ export default class AuthService {
return expirationTime;
}
- static persistUser(hash: string, authClient: WebAuth, setAuthState: any) {
+ static initializeUserSession(
+ hash: string,
+ authClient: WebAuth,
+ setAuthState: any
+ ) {
authClient.parseHash({ hash }, (err, authResult) => {
if (err) {
// TODO: Handle errors
@@ -49,39 +53,41 @@ export default class AuthService {
return new Promise((resolve, reject) => {
this.userExists(email).then((exists) => {
if (exists) {
- reject(new Error('userExists'));
+ reject(new Error("userExists"));
} else {
this.passwordlessStart(authClient, email).then((result) => {
resolve(result);
- })
+ });
}
});
});
};
// Invokes the passwordlessLogin method and following that saves the user to our database
- static completeUserSignup = (authClient: WebAuth,
+ static completeUserSignup = (
+ authClient: WebAuth,
verificationCode: string,
email: string,
name: string,
- organization: (string | null) = null) => {
- this.passwordlessLogin(authClient, email, verificationCode);
- // We need to optimistically save the user to our database here. The user is saved to the _Auth0_
- // database after the passwordlessLogin method succeeds. We also want to save user data in our
- // backend. This should be done after a success callback after passwordlessLogin succceds; however,
- // the passwordlessLogin success callback does not fire within our app, because, upon success, Auth0
- // triggers a redirect to our home page. At that point, we do not have the user's name or organization,
- // which we need to save in our database. Thus, we save the user here.
- //
- // If for some reason, the passwordlessLogin method errors, this code still save the user in our DB.
- // At that point, the worst case scenario is that the user will be informed that they have already
- // signed up if they try to sign up again and to log in instead. Since the Auth0 passwordless flow
- // does not have a sign-up process separate from its log-in process, and thus the user will still
- // be created within Auth0 upon going through our site's log-in flow.
- this.saveUser(email, name, organization);
+ organization: string | null = null
+ ) => {
+ this.passwordlessLogin(authClient, email, verificationCode);
+ // We need to optimistically save the user to our database here. The user is saved to the _Auth0_
+ // database after the passwordlessLogin method succeeds. Following that we need to save user data in our
+ // backend. Ideally, this should be done after a success callback after passwordlessLogin succceds;
+ // however, the passwordlessLogin success callback does not fire within our app, because, upon success, Auth0
+ // triggers a redirect to our home page. At that point, we do not have the user's name or organization,
+ // which we need to save in our database. Thus, we save the user here.
+ //
+ // If for some reason, the passwordlessLogin method errors, this code still save the user in our DB.
+ // At that point, the worst case scenario is that the user will be informed that they have already
+ // signed up if they try to sign up again and to log in instead. The Auth0 passwordless flow does
+ // not have a sign-up process separate from its log-in process, and thus the user will still be
+ // created within Auth0 upon going through our site's log-in flow.
+ this.saveUser(email, name, organization);
};
- // This method initiates the sign-in/sign-up process by sending a code
+ // This method initiates the log-in/sign-up process by sending a code
// to the user's inbox.
static passwordlessStart = (authClient: WebAuth, email: string) => {
return new Promise((resolve, reject) => {
@@ -109,7 +115,7 @@ export default class AuthService {
authClient: WebAuth,
email: string,
verificationCode: string
- ) => {
+ ) => {
authClient.passwordlessLogin(
{
connection: "email",
@@ -138,7 +144,7 @@ export default class AuthService {
};
static hasAccessTokenExpired = (tokenExpiration: Date) => {
- return !tokenExpiration || (new Date(tokenExpiration) < new Date());
+ return !tokenExpiration || new Date(tokenExpiration) < new Date();
};
static refreshAccessToken = (authClient: WebAuth) => {
@@ -155,28 +161,38 @@ export default class AuthService {
static userExists = (email: string) => {
return new Promise((resolve, reject) => {
- post('/api/users/user_exists', {
- email
- }).then((resp) => {
- resp.json().then(result => resolve(result.user_exists));
- }, (error) => {
- reject(error);
- })
+ post("/api/users/user_exists", {
+ email,
+ }).then(
+ (resp) => {
+ resp.json().then((result) => resolve(result.user_exists));
+ },
+ (error) => {
+ reject(error);
+ }
+ );
});
- }
+ };
- static saveUser = (email: string, name: string, organization: (string | null) = null) => {
+ static saveUser = (
+ email: string,
+ name: string,
+ organization: string | null = null
+ ) => {
return new Promise((resolve, reject) => {
- const response = post('/api/users', {
+ const response = post("/api/users", {
email,
name,
organization,
});
- response.then((result) => {
- resolve(result);
- }, (error) => {
- reject(error);
- })
+ response.then(
+ (result) => {
+ resolve(result);
+ },
+ (error) => {
+ reject(error);
+ }
+ );
});
- }
+ };
}
diff --git a/config.example.yml b/config.example.yml
index 072bb9abc..ee577734e 100644
--- a/config.example.yml
+++ b/config.example.yml
@@ -24,4 +24,4 @@ MOHCD_SUBDOMAIN: "testing"
AUTH0_AUDIENCE: "http://localhost:8080/api"
AUTH0_CLIENT_ID: "UcnuRrX6S0SeDEhW9PRe01wEhcvIRuwc"
AUTH0_DOMAIN: "dev-nykixf8szsm220fi.us.auth0.com"
-AUTH0_REDIRECT_URI: "http://localhost:8080"
\ No newline at end of file
+AUTH0_REDIRECT_URI: "http://localhost:8080"