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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Router } from "express";
import { confirmVerification, login, logout, passwordReset, renewAccessToken, requestPasswordReset, sendVerificationEmail } from "../controllers/Auth.js";
import { prefetchUserByEmail } from "../controllers/User.js";
import { validate } from "../utils/handleValidations.js";
import { confirmPasswordResetSchema, confirmVerificationSchema, loginSchema, requestPasswordResetSchema, requestVerificationSchema } from "../validationSchemes/Auth.js";
import { verifyPasswordToken, verifyVerificationToken } from "../utils/handleTokens.js";
const router = Router();
/**
* REQUEST VERIFICATION
*
* @param {string} email [required] email address
*
* @return {string} re-sends a verification email & returns a related message
*/
router.post('/verification',
validate(requestVerificationSchema),
prefetchUserByEmail,
sendVerificationEmail
);
/**
* CONFIRM VERIFICATION
*
* @param {string} token [required] verification token
* @param {string} email [required] email address
*
* @return {string} returns a related message
*/
router.patch('/verification',
validate(confirmVerificationSchema),
// prefetchUserByEmail,
verifyVerificationToken,
confirmVerification
);
/**
* LOGIN
* creates a new access token and refresh token
* refresh token is delivered via cookie
*
* @param {string} email [required] email address
* @param {string} password [required] password
*
* @return {object} user object with JWT
*/
router.post('/login',
validate(loginSchema),
login
);
/**
* RENEW JWT
* renews the short-living access token with the long-living refresh token
*
* @param {cookie} renewAccessToken [required] renewAccessToken via cookie
*
* @return {object} JWT
*/
router.get('/',
renewAccessToken
);
/**
* LOGOUT
* destroys the refresh token in the user record, so no new access token can be created
*
* @return {object} related message
*/
router.delete('/',
logout
);
/**
* REQUEST PASSWORD RESET
*
* @param {email} /password-reset [required] email address
*
* @return {object} related message
*/
router.post('/password-reset',
validate(requestPasswordResetSchema),
requestPasswordReset
);
/**
* PASSWORD RESET
*
* @param {string} token [required] password reset token
* @param {string} password [required] password
* @param {string} confirmPassword [required] password
*
* @return {object} related message
*/
router.patch('/password-reset',
validate(confirmPasswordResetSchema),
verifyPasswordToken,
passwordReset
);
export default router; |