Verify Reddit identity before Matrix capture
This commit is contained in:
1 parent
2fd92bf82c
commit
2c533fa52a
3 files changed
+48
-14
No files matched your search
@@ -33,6 +33,26 @@ export interface AccountAuthContextOptions {
|
||||
now?: () => number;
|
||||
}
|
||||
|
||||
export interface CurrentAccountAuthentication {
|
||||
getRedditUsername(): Promise<string | null>;
|
||||
refreshMatrixCredentials(): Promise<{ userId: string } | null>;
|
||||
}
|
||||
|
||||
export async function authenticateCurrentAccount(
|
||||
authentication: CurrentAccountAuthentication,
|
||||
): Promise<AuthenticatedAccount | null> {
|
||||
const redditUsername = await authentication.getRedditUsername();
|
||||
if (!redditUsername) return null;
|
||||
|
||||
const credentials = await authentication.refreshMatrixCredentials();
|
||||
if (!credentials?.userId) return null;
|
||||
return {
|
||||
accountId: credentials.userId,
|
||||
redditUsername,
|
||||
matrixUserId: credentials.userId,
|
||||
};
|
||||
}
|
||||
|
||||
export const denyAccountAuth: AccountAuthGate = {
|
||||
isFullyAuthenticated: () => false,
|
||||
invalidate: () => undefined,
|
||||
|
||||
Reference in new issue
Block a user