All files / Backend/routes auth.js

95.83% Statements 23/24
75% Branches 3/4
100% Functions 4/4
95.83% Lines 23/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 654x 4x 4x 4x 4x 4x 4x   4x           1x   1x                                 4x           2x   2x 1x           4x 4x 4x 4x 4x       4x 4x     4x     4x  
const express = require('express');
const authController =require('../controllers/auth');
const googleController=require('../controllers/googleAuth');
const {check} = require('express-validator');
const Auth = require('../Authentication/is-auth');
const router= express.Router();
const User=require('../model/user');
 
router.post('/signup',[
 
    check('email')
    .isEmail()
    .withMessage('Please enter a valid email')
    .custom((value,{req})=>{
        return User.findOne({email:value})
        .then(user=>{
            Iif(user){
                return Promise.reject('Email already exists!');
            }
        })
    }),
 
    check('password')
        .trim()
        .isLength({min:5}),
    
    check('name')
        .trim()
        .not()
        .isEmpty() 
 
],authController.signup);
 
router.post('/login',[
 
    check('email')
    .isEmail()
    .withMessage('Please enter a valid email')
    .custom((value,{req})=>{
        return User.findOne({email:value})
        .then(user=>{
            if(!user){
                return Promise.reject('No account with this email !');
            }
        })
 
    })],authController.login);
 
router.post('/signup/otp',authController.otpVerification);
router.post('/signup/resetOtp',authController.resetPassword);
router.post('/signup/otp-resend',authController.resendOtp)
router.post('/signup/checkOtp',authController.resetOtpVerification);
router.post('/signup/reset-password',authController.newPassword);
 
// google authentication route
 
router.post("/google_login",googleController.googleLogin);
router.post("/google_signup",googleController.googleSignUp);
 
// Fetching access Token using refresh token
router.post("/auth/token/",Auth.GetnewAccessToken);
 
 
module.exports = router;