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

Patient Authentication Backend #547

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Patient Authentication Backend #547

wants to merge 19 commits into from

Conversation

Archna-1
Copy link
Contributor

@Archna-1 Archna-1 commented Jan 2, 2022

Status:

🚧 In development

Description

Authenticates patients using Passport.js utilizing patient id's as usernames and secure, randomly generated node-2fa tokens as passwords. Also includes some structural changes to the project, such as:

  • Conditional middleware which determines whether to use AWS or Passport for authentication based on whether there is a session
  • Switches and Routes in AllRoutes instead of AppContent

Fixes #457 #442 #465

Todos

  • Finish up my commented TODOs to clean up code
  • Clean up routing if possible
  • Clean up redirects in patient portal (stretch goal)
  • Clean up navigation to the patient portal without hard coding it
  • Standardize route file naming with other components (?)
  • Change cookie time-out to // null (until the user exits the tab) // Decided on 10 minutes due to shared iPads
  • Confirm cookie timeout after 1 minute again
  • Fix patient portal briefly rendering while checking auth status

Need to Address/Verify Before Merging:

  • Is the current secret for cookies okay?
  • Are we planning on implementing backend translations? It causes Twilio messages to not be sent in Arabic
  • How do I handle only dispatch being used in AWS routes?

Screenshots

None at the moment, but you can pull and try it out yourself! You will need to:

  1. Log out of your account as an admin
  2. Add your phone number to a user in the database
  3. Navigate to localhost:3000/patient-2fa/[patient id of chosen user]
  4. Enter the code you receive from Twilio
  5. Attempt to navigate to localhost:3000/patients or localhost:3000/[restricted route]/[patient id of chosen user]

You should not be able to access anything other than the patient login page and patient portal.

FIXED AS OF 1/2: The patient portal will now redirect if you try to directly access it.

@vercel
Copy link

vercel bot commented Jan 2, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hack4impact/3dp4me/2AkdFRLEHMJY99J9umPpDjC7Pp4t
✅ Preview: https://3dp4me-git-patient-2fa-backend-hack4impact1.vercel.app

@Archna-1 Archna-1 marked this pull request as ready for review January 2, 2022 15:07
@auto-assign auto-assign bot requested a review from suewee January 2, 2022 15:07
Copy link
Collaborator

@mattwalo32 mattwalo32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, this is an amazing amount of progress

@@ -24,7 +27,7 @@ const app = express();
app.use(configureHelment());
app.use(setResponseHeaders);
app.use(express.static(path.join(__dirname, '../frontend/build')));
app.use(cors());
app.use(cors({ credentials: true, origin: 'http://localhost:3000', methods: ['GET', 'POST'] }));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the origin property for this to work? If so, then we need to make origin part of the env vars so that the production environment doesn't have localhost as origin

const sess = {
secret: '3DP4ME',
cookie: {
domain: 'localhost', path: '/', httpOnly: true, secure: false, maxAge: 150000,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue with domain as with origin ^^

if (err) { return err; }
console.log(req.session);
// do i need this line?
req.session.save();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need this line anymore. I'd try without it

console.log('nah');
req.logIn(req.user, (err) => {
if (err) { return err; }
console.log(req.session);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many console.logs that could be removed

);
}
}),
);

router.get(
'/patient-portal/:patientId',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a route for getting a patient by id. It seems like this route would be redundant then. The only difference would be the authentication... I.e. If a volunteer is authenticated, they can view any patient. If a patient is authenticated, they can only view their own data.

So I would just reuse the existing patient endpoint but change the auth middleware on that endpoint so that it allows either type of user to access it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now that I'm looking at this more, it seems like you were just using this endpoint for testing right?

@@ -0,0 +1,28 @@
import React from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is a duplicate file. You have a file named allRoutes and one named AllRoutes and they appear to be the same.

@@ -0,0 +1,148 @@
import React, { useContext, useEffect, useState } from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you also have duplicate AWSRoutes

},
});

export const send2FAPatientCode = async (_id) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused at what this does. It seems like authenticatePatient is the one that actually sends the 2FA code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the endpoint that requests a 2FA code?

@@ -42,7 +61,7 @@ const Patient2FALogin = () => {
<button
className="two-factor-authentication-button"
type="submit"
onClick={() => setIsTokenSent(true)}
onClick={() => onTokenSend()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just replace this with
onClick={onTokenSend}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing with the onChange and onClick below this

const PatientPortal = () => {
const params = useParams();
const { patientId } = params;
const [shouldRender, setShouldRender] = useState();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably make the useState default to something, like false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup Patient Authentication
3 participants