feat(auth): add POST /login with Playwright automation and SQLite session storage
- automates file-key login on the ID portal using Playwright/Chromium - captures token, cookies, and localStorage after successful redirect - stores session data in SQLite via TypeORM (better-sqlite3) - sessions are keyed by sessionName (auto-generated UUID if not provided) - login URL, cabinet redirect URL, keys dir, and DB path are all configurable via env
This commit is contained in:
1 parent
70f016d113
commit
41dbddd2a1
12 files changed
+1478
-22
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { SessionEntity } from './session.entity';
|
||||
import type { Cookie } from 'playwright';
|
||||
|
||||
@Injectable()
|
||||
export class SessionService {
|
||||
constructor(
|
||||
@InjectRepository(SessionEntity)
|
||||
private readonly repo: Repository<SessionEntity>,
|
||||
) {}
|
||||
|
||||
async upsert(
|
||||
sessionName: string,
|
||||
token: string,
|
||||
cookies: Cookie[],
|
||||
localStorage: Record<string, string>,
|
||||
): Promise<SessionEntity> {
|
||||
const existing = await this.repo.findOneBy({ sessionName });
|
||||
|
||||
if (existing) {
|
||||
existing.token = token;
|
||||
existing.cookies = JSON.stringify(cookies);
|
||||
existing.localStorage = JSON.stringify(localStorage);
|
||||
return this.repo.save(existing);
|
||||
}
|
||||
|
||||
return this.repo.save(
|
||||
this.repo.create({
|
||||
sessionName,
|
||||
token,
|
||||
cookies: JSON.stringify(cookies),
|
||||
localStorage: JSON.stringify(localStorage),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
findBySessionName(sessionName: string): Promise<SessionEntity | null> {
|
||||
return this.repo.findOneBy({ sessionName });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user