From 8c55c335cec2be099e560815de6583ad364a34cb Mon Sep 17 00:00:00 2001 From: kj1352 Date: Thu, 21 Oct 2021 16:29:21 +0530 Subject: [PATCH] auth flows with appropriate messages completed --- src/assets/icons/eye-outline.svg | 2 +- src/components/auth/Auth.module.scss | 1 + src/components/auth/Login.tsx | 2 +- src/components/auth/Signup.tsx | 17 +++++++++++++---- src/components/loader/Toast.module.scss | 14 ++++++++++++++ src/components/loader/Toast.tsx | 22 ++++++++++++++++++++++ 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/components/loader/Toast.module.scss create mode 100644 src/components/loader/Toast.tsx diff --git a/src/assets/icons/eye-outline.svg b/src/assets/icons/eye-outline.svg index 68bc62e..5ff1d44 100644 --- a/src/assets/icons/eye-outline.svg +++ b/src/assets/icons/eye-outline.svg @@ -1 +1 @@ -ionicons-v5-i \ No newline at end of file +ionicons-v5-i \ No newline at end of file diff --git a/src/components/auth/Auth.module.scss b/src/components/auth/Auth.module.scss index ccda0a5..0e06aa0 100644 --- a/src/components/auth/Auth.module.scss +++ b/src/components/auth/Auth.module.scss @@ -50,6 +50,7 @@ svg { fill: var(--light-grey); + stroke: var(--light-grey); width: 20px; height: 20px; } diff --git a/src/components/auth/Login.tsx b/src/components/auth/Login.tsx index 1abdea6..03991be 100644 --- a/src/components/auth/Login.tsx +++ b/src/components/auth/Login.tsx @@ -7,7 +7,7 @@ import { NavLink } from "react-router-dom"; import axios from 'axios'; import { SERVER_URL } from "../../App"; -const authenticateCredentials = async (username: string, password: string) => { +export const authenticateCredentials = async (username: string, password: string) => { return await axios.post(SERVER_URL + '/auth/api-auth/', { email: username, password: password diff --git a/src/components/auth/Signup.tsx b/src/components/auth/Signup.tsx index 755badc..77be0c2 100644 --- a/src/components/auth/Signup.tsx +++ b/src/components/auth/Signup.tsx @@ -6,6 +6,7 @@ import { ReactComponent as EyeIcon } from '../../assets/icons/eye-outline.svg'; import { NavLink } from "react-router-dom"; import axios from 'axios'; import { SERVER_URL } from "../../App"; +import { authenticateCredentials } from "./Login"; const registerUser = async (name: string, username: string, password: string) => { @@ -40,6 +41,7 @@ export const Signup: React.FC = () => { function register() { registerUser(fullName, userName, password).then(() => { + window.alert("Registered your email, please wait while we redirect you to verify..."); setTimeout(() => { requestVerification(userName).then(() => { @@ -56,8 +58,15 @@ export const Signup: React.FC = () => { function verify() { verifyUser(userName, otp).then(() => { - window.alert("Verified user!"); - window.location.assign("/login"); + window.alert("Verified user!, Logging you in...."); + + authenticateCredentials(userName, password).then((response: any) => { + localStorage.anamnesisToken = response.data.token; + window.location.assign('/home'); + }, () => { + window.alert("Please check your credentials"); + }); + }, () => window.alert("Failed Verification, please try again")) } @@ -87,10 +96,10 @@ export const Signup: React.FC = () => { - Login? + Login? } diff --git a/src/components/loader/Toast.module.scss b/src/components/loader/Toast.module.scss new file mode 100644 index 0000000..dc8724c --- /dev/null +++ b/src/components/loader/Toast.module.scss @@ -0,0 +1,14 @@ +.toast { + position: fixed; + bottom: 5vh; + left: 5vw; + width: 90vw; + border-radius: 10px; + background-color: var(--red); + color: white; + padding: 10px 15px; + font-size: 16px; + font-weight: 500; + letter-spacing: 0.5px; + opacity: 0.8; +} \ No newline at end of file diff --git a/src/components/loader/Toast.tsx b/src/components/loader/Toast.tsx new file mode 100644 index 0000000..7b92101 --- /dev/null +++ b/src/components/loader/Toast.tsx @@ -0,0 +1,22 @@ +import React from "react"; +import styles from './Toast.module.scss'; + + +type OwnProps = { + type: 'success' | 'warning' | 'error', + message: string, +} + +export const Toast: React.FC = (props) => { + let toastStyle = ''; + + switch(props.type) { + case 'success' : toastStyle = styles.success; break; + case 'warning': toastStyle = styles.warning; break; + case 'error': toastStyle = styles.error; break; + } + + return
+ { props.message } +
+} \ No newline at end of file