Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
BACKEND CHALLENGES
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phạm Quang Bảo
BACKEND CHALLENGES
Commits
e5df0aa7
Commit
e5df0aa7
authored
May 19, 2026
by
Phạm Quang Bảo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(challenge_5): add api logout and auth
parent
994cb722
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
95 additions
and
4 deletions
+95
-4
index.ts
code/src/controllers/api/v1.0/auth/logout/index.ts
+44
-0
index.ts
code/src/controllers/api/v1.0/auth/profile/index.ts
+1
-1
index.ts
code/src/controllers/api/v1.0/auth/send-otp/index.ts
+1
-1
index.ts
code/src/controllers/api/v1.0/auth/verify-otp/index.ts
+1
-1
swagger-output.json
code/src/docs/swagger/swagger-output.json
+33
-0
index.ts
code/src/index.ts
+1
-1
authentication.ts
code/src/middlewares/authentication.ts
+0
-0
config.ts
code/src/templates/swagger/config.ts
+2
-0
schema.ts
code/src/templates/swagger/logout/schema.ts
+12
-0
No files found.
code/src/controllers/api/v1.0/auth/logout/index.ts
0 → 100644
View file @
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
code/src/controllers/api/v1.0/auth/profile/index.ts
View file @
e5df0aa7
import
{
authMiddleware
}
from
"#middlewares/auth
oriz
ation"
;
import
{
authMiddleware
}
from
"#middlewares/auth
entic
ation"
;
import
{
AuthService
}
from
"#services/authService"
;
import
{
AuthService
}
from
"#services/authService"
;
import
{
Application
}
from
"express"
;
import
{
Application
}
from
"express"
;
import
{
Resource
}
from
"express-automatic-routes"
;
import
{
Resource
}
from
"express-automatic-routes"
;
...
...
code/src/controllers/api/v1.0/auth/send-otp/index.ts
View file @
e5df0aa7
import
{
authMiddleware
}
from
"#middlewares/auth
oriz
ation"
;
import
{
authMiddleware
}
from
"#middlewares/auth
entic
ation"
;
import
{
AuthService
}
from
"#services/authService.js"
;
import
{
AuthService
}
from
"#services/authService.js"
;
import
{
MailService
}
from
"#services/mailService.js"
;
import
{
MailService
}
from
"#services/mailService.js"
;
import
{
Application
}
from
"express"
;
import
{
Application
}
from
"express"
;
...
...
code/src/controllers/api/v1.0/auth/verify-otp/index.ts
View file @
e5df0aa7
import
{
authMiddleware
}
from
"#middlewares/auth
oriz
ation"
;
import
{
authMiddleware
}
from
"#middlewares/auth
entic
ation"
;
import
{
AuthService
}
from
"#services/authService.js"
;
import
{
AuthService
}
from
"#services/authService.js"
;
import
{
Application
}
from
"express"
;
import
{
Application
}
from
"express"
;
import
{
Resource
}
from
"express-automatic-routes"
;
import
{
Resource
}
from
"express-automatic-routes"
;
...
...
code/src/docs/swagger/swagger-output.json
View file @
e5df0aa7
...
@@ -350,6 +350,14 @@
...
@@ -350,6 +350,14 @@
"example"
:
"123456"
"example"
:
"123456"
}
}
}
}
},
"logoutResponse"
:
{
"type"
:
"object"
,
"properties"
:
{
"message"
:
{
"type"
:
"string"
}
}
}
}
},
},
"parameters"
:
{
"parameters"
:
{
...
@@ -421,6 +429,31 @@
...
@@ -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"
:
{
"/api/v1.0/auth/profile"
:
{
"get"
:
{
"get"
:
{
"tags"
:
[
"tags"
:
[
...
...
code/src/index.ts
View file @
e5df0aa7
...
@@ -20,5 +20,5 @@ _autoroutes(app, {
...
@@ -20,5 +20,5 @@ _autoroutes(app, {
app
.
use
(
'/swagger'
,
swaggerUi
.
serve
,
swaggerUi
.
setup
(
swaggerFile
));
app
.
use
(
'/swagger'
,
swaggerUi
.
serve
,
swaggerUi
.
setup
(
swaggerFile
));
app
.
listen
(
port
,
()
=>
{
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`
Example a
pp listening on port
${
port
}
`
)
console
.
log
(
`
A
pp listening on port
${
port
}
`
)
})
})
code/src/middlewares/auth
oriz
ation.ts
→
code/src/middlewares/auth
entic
ation.ts
View file @
e5df0aa7
File moved
code/src/templates/swagger/config.ts
View file @
e5df0aa7
...
@@ -8,6 +8,7 @@ import loginSchemas from './login/schemas.js';
...
@@ -8,6 +8,7 @@ import loginSchemas from './login/schemas.js';
import
authProfileSchemas
from
'./authProfile/schema.js'
;
import
authProfileSchemas
from
'./authProfile/schema.js'
;
import
sendOTPSchemas
from
'./sendOTP/schema.js'
;
import
sendOTPSchemas
from
'./sendOTP/schema.js'
;
import
verifyOTPSchemas
from
'./verifyOTP/schema.js'
;
import
verifyOTPSchemas
from
'./verifyOTP/schema.js'
;
import
logoutSchemas
from
'./logout/schema.js'
;
const
swaggerOptions
:
Options
=
{
const
swaggerOptions
:
Options
=
{
definition
:
{
definition
:
{
...
@@ -32,6 +33,7 @@ const swaggerOptions: Options = {
...
@@ -32,6 +33,7 @@ const swaggerOptions: Options = {
...
authProfileSchemas
,
...
authProfileSchemas
,
...
sendOTPSchemas
,
...
sendOTPSchemas
,
...
verifyOTPSchemas
,
...
verifyOTPSchemas
,
...
logoutSchemas
,
},
},
parameters
:
{
parameters
:
{
filters
:
{
filters
:
{
...
...
code/src/templates/swagger/logout/schema.ts
0 → 100644
View file @
e5df0aa7
const
logoutSchema
=
{
logoutResponse
:
{
type
:
"object"
,
properties
:
{
message
:
{
type
:
"string"
}
}
}
};
export
default
logoutSchema
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment