fix(auth): unify imported sessions with account gating
This commit is contained in:
1 parent
654bbda457
commit
ea92a1a92b
15 files changed
+123
-49
No files matched your search
@@ -19,9 +19,8 @@ const ROOM_URL_PREFIX = 'https://chat.reddit.com/room/';
|
||||
|
||||
export interface TokenRefresher {
|
||||
/**
|
||||
* Re-extract a fresh Matrix bearer token (e.g. by re-running the browser
|
||||
* sniff against the persistent session) and apply it to the underlying
|
||||
* client. Resolves when the client is ready to be retried.
|
||||
* Requests replacement Matrix credentials. Extension-only authentication
|
||||
* deliberately rejects this until the user imports a fresh dump.
|
||||
*/
|
||||
refresh(): Promise<void>;
|
||||
}
|
||||
@@ -175,9 +174,8 @@ export class ChatService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a Matrix call; if it 401/403s, re-extract the bearer via the
|
||||
* configured `TokenRefresher` and retry once. Single retry only — if the
|
||||
* refresh itself fails, we propagate.
|
||||
* Run a Matrix call; if it 401/403s, invalidate the shared account gate.
|
||||
* The configured refresher reports that a new extension dump is required.
|
||||
*/
|
||||
private async withAuth<T>(fn: () => Promise<T>): Promise<T> {
|
||||
if (!this.accountAuth?.isFullyAuthenticated()) {
|
||||
@@ -189,7 +187,7 @@ export class ChatService {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
if (err instanceof MatrixAuthError && this.tokenRefresher) {
|
||||
this.logger.warn('[chat] Matrix token rejected — refreshing via browser session');
|
||||
this.logger.warn('[chat] Matrix token rejected — waiting for a new extension dump');
|
||||
try {
|
||||
await this.tokenRefresher.refresh();
|
||||
} catch (refreshError) {
|
||||
|
||||
Reference in new issue
Block a user