token refresh
This commit is contained in:
parent
bcfba8b448
commit
55caf69bf0
4 changed files with 102 additions and 8 deletions
26
src/service/refreshService.ts
Normal file
26
src/service/refreshService.ts
Normal 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");
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue