server/utils/auth.ts

17 lines
305 B
TypeScript
Raw Normal View History

2023-09-13 21:02:16 +02:00
import { Token } from "~database/entities/Token";
export const getUserByToken = async (access_token: string | null) => {
if (!access_token) return null;
2023-09-22 03:09:14 +02:00
const token = await Token.findOne({
where: {
access_token,
},
relations: ["user"],
2023-09-13 21:02:16 +02:00
});
if (!token) return null;
return token.user;
};