Skip to content

Commit

Permalink
Auth Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhalevedant06 committed Dec 3, 2022
1 parent 794b43c commit d147e73
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion client/src/pages/landing/loginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import StyledButton from "../../components/CustomButton/StyledButton";
import axios from "../../utils/axiosInstance";

import { CustomTextField } from "../../globals/global.styles";
import { useNavigate } from "react-router-dom";

const LoginPage = ({ setMode }) => {
const [role, setRole] = useState("");
const [email,setEmail] = useState();
const navigate = useNavigate()

const handleLogin = async()=>{
const data = {
email
}
const response = await axios.post('/auth/login',data);
console.log(response)
localStorage.setItem("Token", response?.data?.data._id);
navigate(`/verify/${response?.data?.data._id}`);
}

return (
Expand Down
5 changes: 4 additions & 1 deletion client/src/pages/landing/signupPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TextField, styled } from "@mui/material";
import React, { useState } from "react";
import StyledButton from "../../components/CustomButton/StyledButton";
import axios from "../../utils/axiosInstance";

import { useNavigate } from "react-router-dom";
const CustomTextField = styled(TextField)(() => ({
"& label.Mui-focused": {
color: "rgba(255, 255, 255, 0.685)",
Expand All @@ -29,6 +29,7 @@ const CustomTextField = styled(TextField)(() => ({
const SignupPage = ({ setMode }) => {
const [role, setRole] = useState(null);
const [data,setData] = useState()
const navigate = useNavigate()

const handleChange = (e) => {
setData({
Expand All @@ -42,6 +43,8 @@ const SignupPage = ({ setMode }) => {
console.log(data);
const response = await axios.post('/auth/signup',data);
console.log(response);
localStorage.setItem("Token", response?.data?.data._id);
navigate(`/verify/${response?.data?.data._id}`);
}

return (
Expand Down
18 changes: 16 additions & 2 deletions client/src/pages/landing/verify.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { CustomTextField } from "../../globals/global.styles";
import { Box, styled } from "@mui/material";
// import CustomButton from "../../components/CustomButton/CustomButton.component";
import StyledButton from "../../components/CustomButton/StyledButton";
import axios from "../../utils/axiosInstance";
// import LandingPage from "./landingPage";
// import SignupPage from "./signupPage";
// import LoginPage from "./loginPage";
import { useNavigate, useParams } from "react-router-dom";

const Glass = styled(Box)(() => ({
width: "100vw",
Expand All @@ -25,6 +27,18 @@ const Glass = styled(Box)(() => ({

const Landing = () => {
const [mode, setMode] = useState("landing");
const [otp,setOTP] = useState();
let { id } = useParams();
const navigate = useNavigate();

const handleVerify = async()=>{
const data = {
otp
}
const response = await axios.post(`/auth/validateOTP/${id}`,data)
console.log(response);
navigate('/reader/home')
}

// let content;

Expand Down Expand Up @@ -131,9 +145,9 @@ const Landing = () => {
<h1 className="font-semibold text-2xl text-text1">
Please enter the OTP sent to your email to verify yourself!
</h1>
<CustomTextField label="Enter OTP" fullWidth />
<CustomTextField onChange={(e)=>setOTP(e.target.value)} label="Enter OTP" name="otp" fullWidth />

<StyledButton>VERIFY</StyledButton>
<StyledButton onClick={()=>handleVerify()}>VERIFY</StyledButton>
{/* <div className="text-text1">
New to debinder?{" "}
<button
Expand Down
2 changes: 1 addition & 1 deletion server/models/token.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const tokenSchema = new Schema({
createdAt: {
type: Date,
default: Date.now,
expires: 120,
expires: 3600,
},
});

Expand Down

0 comments on commit d147e73

Please sign in to comment.