Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmamaqi committed Jul 3, 2023
1 parent 2af3c90 commit df7290d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions back/src/__tests__/auth/logout.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import supertest from 'supertest'
import { expect, test, describe } from 'vitest'
import { server } from '../globalSetup'
import { pathRoot } from '../../routes/routes'

describe('Testing authentication endpoint', () => {
test('should succeed', async () => {
const response = await supertest(server).get(`${pathRoot.v1.auth}/logout`)
expect(response.status).toBe(204)
})
})
6 changes: 6 additions & 0 deletions back/src/controllers/auth/logoutController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Context } from 'koa'

export const logoutController = async (ctx: Context) => {
ctx.cookies.set('token', null)
ctx.status = 204
}
1 change: 1 addition & 0 deletions back/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { loginController } from './auth/loginController'
export { logoutController } from './auth/logoutController'
export { registerController } from './auth/registerController'
export { authMeController } from './auth/authMeController'
export { createResource } from './resources/createResourceController'
Expand Down
3 changes: 3 additions & 0 deletions back/src/routes/authRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'
import {
authMeController,
loginController,
logoutController,
registerController,
} from '../controllers'
import { validate, authMiddleware } from '../middleware'
Expand All @@ -19,6 +20,8 @@ authRouter.post(
loginController
)

authRouter.get('/logout', logoutController)

authRouter.post(
'/register',
validate(z.object({ body: userRegisterSchema })),
Expand Down

0 comments on commit df7290d

Please sign in to comment.