Merge pull request #46 from KeyZox71/adding-logout-auth

」 feat(auth-api): /logout added (closes #47)
This commit is contained in:
Adam
2025-10-07 16:55:02 +02:00
committed by GitHub
3 changed files with 45 additions and 0 deletions

24
doc/auth/logout.md Normal file
View File

@ -0,0 +1,24 @@
# Logout
Available endpoints:
- GET `/logout`
Common return:
- 500 with response
```json
{
"error": "Internal server error"
}
```
## GET `/logout`
Used to logout the client (it just delete the cookie)
Returns:
- 200 with response and clear cookie
```json
{
"msg": "Logout successful"
}
```

View File

@ -10,6 +10,7 @@ import { gRegisterCallback } from './gRegisterCallback.js';
import { totpSetup } from './totpSetup.js';
import { totpDelete } from './totpDelete.js';
import { totpVerify } from './totpVerify.js';
import { logout } from './logout.js';
const saltRounds = 10;
export const appName = process.env.APP_NAME || 'knl_meowscendence';
@ -107,4 +108,6 @@ export default async function(fastify, options) {
}
}
}, async (request, reply) => { return register(request, reply, saltRounds, fastify); });
fastify.get('/logout', {}, async (request, reply) => { return logout(reply, fastify); })
}

18
src/api/auth/logout.js Normal file
View File

@ -0,0 +1,18 @@
/**
* @async
* @param {import("fastify").FastifyReply} reply
* @param {import("fastify").FastifyInstance} fastify
*
* @returns {import("fastify").FastifyReply}
*/
export async function logout(reply, fastify) {
try {
return reply
.code(200)
.clearCookie("token")
.send({ msg: "Logout successful" });
} catch {
fastify.log.error(err);
return reply.code(500).send({ error: "Internal server error" });
}
}