token refresh

This commit is contained in:
Julian Krauser 2024-08-23 14:42:47 +02:00
parent bcfba8b448
commit 55caf69bf0
4 changed files with 102 additions and 8 deletions

View file

@ -0,0 +1,26 @@
import { dataSource } from "../data-source";
import { refresh } from "../entity/refresh";
import InternalException from "../exceptions/internalException";
export default abstract class RefreshService {
/**
* @description get refresh by token
* @param token string
* @returns {Promise<refresh>}
*/
static async getByToken(token: string): Promise<refresh> {
return await dataSource
.getRepository(refresh)
.createQueryBuilder("refresh")
.leftJoinAndSelect("refresh.user", "user")
.where("refresh.token = :token", { token: token })
.andWhere("refresh.expiry >= :expiry", { expiry: new Date() })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("refresh not found");
});
}
}