mirror of
https://github.com/apricote/Listory.git
synced 2026-02-06 17:57:03 +00:00
feat: implement long-lived sessions
This commit is contained in:
parent
d0705afca8
commit
44f7e26270
35 changed files with 739 additions and 190 deletions
23
src/auth/auth-session.repository.ts
Normal file
23
src/auth/auth-session.repository.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// tslint:disable: max-classes-per-file
|
||||
import { EntityRepository, Repository, SelectQueryBuilder } from "typeorm";
|
||||
import { User } from "../users/user.entity";
|
||||
import { AuthSession } from "./auth-session.entity";
|
||||
|
||||
export class AuthSessionScopes extends SelectQueryBuilder<AuthSession> {
|
||||
/**
|
||||
* `byUser` scopes the query to AuthSessions created by the user.
|
||||
* @param currentUser
|
||||
*/
|
||||
byUser(currentUser: User): this {
|
||||
return this.andWhere(`session."userId" = :userID`, {
|
||||
userID: currentUser.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EntityRepository(AuthSession)
|
||||
export class AuthSessionRepository extends Repository<AuthSession> {
|
||||
get scoped(): AuthSessionScopes {
|
||||
return new AuthSessionScopes(this.createQueryBuilder("session"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue