35 lines
1,013 B
TypeScript
35 lines
1,013 B
TypeScript
export type ValidAuthProvider = "Discord" | "GitHub";
|
|
|
|
// Can't send the providers across the wire, do this instead
|
|
export type AuthProviderState = {
|
|
name: ValidAuthProvider;
|
|
} & ({ connected: false } | { connected: true; id: string; username: string });
|
|
|
|
export abstract class AuthProvider {
|
|
protected readonly accessToken: string;
|
|
|
|
constructor(accessToken: string) {
|
|
this.accessToken = accessToken;
|
|
}
|
|
|
|
abstract isPermitted(): Promise<boolean>;
|
|
abstract getId(): Promise<string>;
|
|
|
|
// this difference only really matters for discordd
|
|
// display name:
|
|
// - discord: username
|
|
// - github: username
|
|
// username:
|
|
// - discord: username#discriminator
|
|
// - github: username
|
|
abstract getDisplayName(): Promise<string>;
|
|
abstract getUsername(): Promise<string>;
|
|
|
|
// these two aren't null for github
|
|
abstract getAvatar(): Promise<string | null>;
|
|
abstract getEmail(): Promise<string | null>;
|
|
|
|
static get redirectUri(): string {
|
|
throw new Error("Not implemented");
|
|
}
|
|
}
|