fase(9): auth module with casl rbac and session management
This commit is contained in:
46
dist/modules/auth/infrastructure/repositories/KyselySessionRepository.js
vendored
Normal file
46
dist/modules/auth/infrastructure/repositories/KyselySessionRepository.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KyselySessionRepository = void 0;
|
||||
class KyselySessionRepository {
|
||||
constructor(db) {
|
||||
this.db = db;
|
||||
}
|
||||
async save(session) {
|
||||
await this.db
|
||||
.insertInto('auth_sessions')
|
||||
.values({
|
||||
id: session.id,
|
||||
user_id: session.userId,
|
||||
token: session.token,
|
||||
expires_at: session.expiresAt.getTime(),
|
||||
created_at: session.createdAt.getTime(),
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
async findByToken(token) {
|
||||
const row = await this.db
|
||||
.selectFrom('auth_sessions')
|
||||
.selectAll()
|
||||
.where('token', '=', token)
|
||||
.executeTakeFirst();
|
||||
if (!row)
|
||||
return undefined;
|
||||
return {
|
||||
id: row.id,
|
||||
userId: row.user_id,
|
||||
token: row.token,
|
||||
expiresAt: new Date(row.expires_at),
|
||||
createdAt: new Date(row.created_at),
|
||||
};
|
||||
}
|
||||
async deleteByToken(token) {
|
||||
await this.db.deleteFrom('auth_sessions').where('token', '=', token).execute();
|
||||
}
|
||||
async deleteExpired() {
|
||||
await this.db
|
||||
.deleteFrom('auth_sessions')
|
||||
.where('expires_at', '<', Date.now())
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
exports.KyselySessionRepository = KyselySessionRepository;
|
||||
Reference in New Issue
Block a user