Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 28 additions & 243 deletions src/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,10 @@ import { googleVerifyIdToken } from '../utils/googleVerifyToken.utils.js';

/* eslint no-undef:off */
/**
* @swagger
* /api/auth/signup:
* post:
* summary: Register a new user
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - password
* - firstName
* - lastName
* - username
* properties:
* email:
* type: string
* password:
* type: string
* firstName:
* type: string
* lastName:
* type: string
* username:
* type: string
* responses:
* 201:
* description: User created successfully
* 400:
* description: Bad request
* 500:
* description: Server error
* @desc Creates a new user account and sends verification OTP to email
* @route /api/auth/signup
* @method POST
* @access public
*/
export const signup = async (req, res, next) => {
try {
Expand Down Expand Up @@ -120,34 +89,10 @@ export const signup = async (req, res, next) => {
};

/**
* @swagger
* /api/auth/verifyEmail:
* post:
* summary: Verify user's email address using OTP
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - otp
* properties:
* email:
* type: string
* otp:
* type: string
* responses:
* 200:
* description: Email verified successfully
* 400:
* description: Invalid or expired OTP
* 404:
* description: User not found
* 500:
* description: Server error
* @desc Verify user's email address using the OTP sent to their email
* @route /api/auth/verifyEmail
* @method POST
* @access public
*/
export const verifyEmail = async (req, res, next) => {
try {
Expand Down Expand Up @@ -191,54 +136,10 @@ export const verifyEmail = async (req, res, next) => {
};

/**
* @swagger
* /api/auth/signin:
* post:
* summary: Authenticate user and get access token
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - password
* properties:
* email:
* type: string
* password:
* type: string
* responses:
* 200:
* description: Login successful
* content:
* application/json:
* schema:
* type: object
* properties:
* accessToken:
* type: string
* refreshToken:
* type: string
* user:
* type: object
* properties:
* id:
* type: string
* email:
* type: string
* name:
* type: string
* role:
* type: string
* 401:
* description: Invalid credentials
* 403:
* description: Account not activated
* 500:
* description: Server error
* @desc Authenticate user and return JWT tokens
* @route /api/auth/signin
* @method POST
* @access public
*/
export const signin = async (req, res, next) => {
try {
Expand Down Expand Up @@ -299,27 +200,10 @@ export const signin = async (req, res, next) => {
};

/**
* @swagger
* /api/auth/forgotPassword:
* post:
* summary: Request password reset OTP
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* properties:
* email:
* type: string
* responses:
* 200:
* description: Password reset OTP sent if account exists
* 500:
* description: Server error
* @desc Initiate password reset process by sending OTP to user's email
* @route /api/auth/forgotPassword
* @method POST
* @access public
*/
export const forgotPassword = async (req, res, next) => {
try {
Expand Down Expand Up @@ -369,37 +253,10 @@ export const forgotPassword = async (req, res, next) => {
};

/**
* @swagger
* /api/auth/resetPassword:
* post:
* summary: Reset password using OTP
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - email
* - otp
* - newPassword
* properties:
* email:
* type: string
* otp:
* type: string
* newPassword:
* type: string
* responses:
* 200:
* description: Password reset successful
* 400:
* description: Invalid or expired OTP
* 404:
* description: User not found
* 500:
* description: Server error
* @desc Reset user password using the OTP received via email
* @route /api/auth/resetPassword
* @method POST
* @access public
*/
export const resetPassword = async (req, res, next) => {
try {
Expand Down Expand Up @@ -449,38 +306,10 @@ export const resetPassword = async (req, res, next) => {
};

/**
* @swagger
* /api/auth/refreshAccessToken:
* post:
* summary: Get new access token using refresh token
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - refreshToken
* properties:
* refreshToken:
* type: string
* responses:
* 200:
* description: New access token generated
* content:
* application/json:
* schema:
* type: object
* properties:
* accessToken:
* type: string
* 400:
* description: Refresh token is required
* 401:
* description: Invalid refresh token
* 500:
* description: Server error
* @desc Generate new access token using refresh token
* @route /api/auth/refreshAccessToken
* @method POST
* @access public
*/
export const refreshAccessToken = async (req, res, next) => {
try {
Expand Down Expand Up @@ -527,54 +356,10 @@ export const googleOAuthCallback = (req, res) => {
};

/**
* @swagger
* /auth/google:
* post:
* summary: Authenticate or register user using Google OAuth (for mobile/SPA)
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - idToken
* properties:
* idToken:
* type: string
* responses:
* 200:
* description: Google authentication successful
* content:
* application/json:
* schema:
* type: object
* properties:
* user:
* type: object
* properties:
* id:
* type: string
* email:
* type: string
* name:
* type: string
* role:
* type: string
* profilePic:
* type: string
* tokens:
* type: object
* properties:
* accessToken:
* type: string
* refreshToken:
* type: string
* 400:
* description: Google authentication failed
* 500:
* description: Server error
* @desc Authenticate or register user using Google OAuth
* @route /api/auth/google
* @method POST
* @access public
*/
export const googleOAuthLogin = async (req, res) => {
try {
Expand Down
Loading