Commit 59dd600b authored by Nguyễn Thị Nguyệt Quế's avatar Nguyễn Thị Nguyệt Quế

Merge branch 'feat/challenge_5_api_logout' into 'develop'

feat(challenge_5): add api logout and auth

See merge request !5
parents 994cb722 e5df0aa7
import { authMiddleware } from "#middlewares/authentication";
import { AuthService } from "#services/authService";
import { Application } from "express";
import { Resource } from "express-automatic-routes";
export default (_express: Application) => {
const authService = new AuthService();
return <Resource>{
/**
* @openapi
* /api/v1.0/auth/logout:
* post:
* tags: [Auth]
* security:
* - bearerAuth: []
* description: Đăng xuất người dùng
* responses:
* 200:
* description: Đăng xuất thành công
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/logoutResponse"
*/
post: {
middleware: [authMiddleware],
handler: async (req, res) => {
try {
const userId = (req as any).user.id;
console.log('User ID to logout:', userId);
return res.status(200).json({
message: 'Đăng xuất thành công',
});
} catch (error) {
return res.status(500).json({ error: (error as Error).message });
}
}
}
}
}
\ No newline at end of file
import { authMiddleware } from "#middlewares/authorization";
import { authMiddleware } from "#middlewares/authentication";
import { AuthService } from "#services/authService";
import { Application } from "express";
import { Resource } from "express-automatic-routes";
......
import { authMiddleware } from "#middlewares/authorization";
import { authMiddleware } from "#middlewares/authentication";
import { AuthService } from "#services/authService.js";
import { MailService } from "#services/mailService.js";
import { Application } from "express";
......
import { authMiddleware } from "#middlewares/authorization";
import { authMiddleware } from "#middlewares/authentication";
import { AuthService } from "#services/authService.js";
import { Application } from "express";
import { Resource } from "express-automatic-routes";
......
......@@ -350,6 +350,14 @@
"example": "123456"
}
}
},
"logoutResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
},
"parameters": {
......@@ -421,6 +429,31 @@
}
}
},
"/api/v1.0/auth/logout": {
"post": {
"tags": [
"Auth"
],
"security": [
{
"bearerAuth": []
}
],
"description": "Đăng xuất người dùng",
"responses": {
"200": {
"description": "Đăng xuất thành công",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/logoutResponse"
}
}
}
}
}
}
},
"/api/v1.0/auth/profile": {
"get": {
"tags": [
......
......@@ -20,5 +20,5 @@ _autoroutes(app, {
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerFile));
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
console.log(`App listening on port ${port}`)
})
......@@ -8,6 +8,7 @@ import loginSchemas from './login/schemas.js';
import authProfileSchemas from './authProfile/schema.js';
import sendOTPSchemas from './sendOTP/schema.js';
import verifyOTPSchemas from './verifyOTP/schema.js';
import logoutSchemas from './logout/schema.js';
const swaggerOptions: Options = {
definition: {
......@@ -32,6 +33,7 @@ const swaggerOptions: Options = {
...authProfileSchemas,
...sendOTPSchemas,
...verifyOTPSchemas,
...logoutSchemas,
},
parameters: {
filters: {
......
const logoutSchema = {
logoutResponse: {
type: "object",
properties: {
message: {
type: "string"
}
}
}
};
export default logoutSchema;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment