Skip to main content

Signing in a Nurse Using Magic Link

This guide will walk you through the process of signing in a nurse using a magic link. The magic link allows a nurse to sign in without needing to enter a password. This process involves requesting a magic link, receiving it via email, and using it to sign in.

To request a magic link, the nurse needs to provide their email address. The system will send an email containing the magic link to the provided email address.

GraphQL Mutation:

mutation NurseRequestMagicLink($email: String!) {
requestMagicLinkForNurse(email: $email) {
success
message
}
}

Variables:

{  
"email": "nurse@example.com"
}

Expected Response:

{
"data": {
"requestMagicLinkForNurse": {
"success": true,
"message": "If you have an account with email: nurse@example.com, you will receive a magic link to sign in."
}
}
}

The nurse will receive an email with a magic link. The email will look something like this:

<html>
<body>
<p>Hello [Nurse Name],</p>
<p>You have requested a magic link to sign in to your account. Please click the link below to sign in.</p>
<p>Click <a href="http://localhost:4200/magic-link?token=[TOKEN]">here</a> to sign in.</p>
<p>If you did not request this, please ignore this email.</p>
<p>Thank you,</p>
<p>The MedTrack Team</p>
</body>
</html>

Before using the magic link to sign in, the token needs to be verified. This step ensures that the token is valid and has not expired.

GraphQL Mutation:

mutation VerifyMagicLinkToken($token: String!, $email: String!, $userType: String!) {
verifyMagicLinkToken(token: $token, email: $email, userType: $userType) {
success
magicLinkToken
}
}

Variables:

{    
"token": "[TOKEN]",
"email": "nurse@example.com",
"userType": "nurse"
}

Expected Response:

{
"data": {
"verifyMagicLinkToken": {
"success": true,
"magicLinkToken": "[MAGIC_LINK_TOKEN]"
}
}
}

Once the token is verified, the nurse can use the magic link token to sign in.

GraphQL Query:

query NurseSignInWithMagicLink($magicLinkToken: String!) {
nurseSignInWithMagicLink(magicLinkToken: $magicLinkToken) {
id
token
firstName
lastName
email
}
}

Variables:

{    
"magicLinkToken": "[MAGIC_LINK_TOKEN]"
}

Expected Response:

{
"data": {
"nurseSignInWithMagicLink": {
"id": "1",
"token": "[JWT_TOKEN]",
"firstName": "Nurse",
"lastName": "Example",
"email": "nurse@example.com"
}
}
}

Summary

By following these steps, a nurse can sign in using a magic link. This process involves requesting a magic link, verifying the token, and using it to sign in. Ensure that the email address provided is correct and that the token is used within its validity period.

Flow Diagram