Skip to content

Commit a1dc4c7

Browse files
committed
modification signUot and token preHandler checkToken
1 parent 557cfb7 commit a1dc4c7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

app/components/auth/signOut.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export const signOut = async (server: FastifyInstance) => {
3232
'/signout',
3333
options,
3434
async (req, reply) => {
35-
await server.pg.query('delete from root.users_access where token = $1', [req.body.token]);
36-
reply.send();
35+
const {rowCount} = await server.pg.query('delete from root.users_access where token = $1 AND expires > current_timestamp', [req.body.token]);
36+
37+
rowCount ? reply.send() : reply.status(500).send();
3738
}
3839
);
3940
};

app/hooks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export const checkToken = async <A, B, C, RouteGeneric> (req: FastifyRequest<Rou
1616
const token = req.body?.token || req.headers?.token;
1717

1818
if (token) {
19-
const {rows} = await server.pg.query('select user_id from root.users_access where token=$1', [token]);
19+
const {rows} = await server.pg.query('select user_id from root.users_access where token=$1 AND expires > current_timestamp', [token]);
2020
if (!rows.length) {
2121
reply.status(401).send();
2222
return reply;
2323
}
24-
req.headers.userId = rows[0].user_id;
24+
req.headers.userId = rows[0].user_id;//todo проверить что отдается в ответе от сервера
2525
} else {
2626
reply.status(401).send();
2727
return reply;

0 commit comments

Comments
 (0)