DiscordAPI
serverapp/features/discord/core/DiscordAPI.server.tsNo overview comment at the top of the file.
- Imports
- no other modules
- Used by
- 2 routes1 module
Types
export type DiscordTokens = OAuth2Strategy.VerifyOptions["tokens"];
Functions & values
OAuth flow of the linked role verification URL. Separate from log in: it asks for the role_connections.write scope and the tokens are stored to update the metadata later.
export const linkedRoleStrategy = new OAuth2Strategy<DiscordTokens>( { clientId: ServerConfig.discord.clientId, clientSecret: ServerConfig.discord.clientSecret, authorizationEndpoint: "https://discord.com/api/oauth2/authorize", tokenEndpoint: `${API_URL}/oauth2/token`, redirectURI: new URL(LINKED_ROLE_CALLBACK_URL, Config.siteDomain), scopes: ["identify", "role_connections.write"], cookie: { name: "discord_linked_role",
Discord id of the user the access token belongs to.
export async function fetchUserId(accessToken: string)
New tokens for the refresh token, null if Discord no longer accepts it (e.g. the user deauthorized the app).
export async function refreshTokens( refreshToken: string, ): Promise<DiscordTokens | null>
Replaces the user's linked role metadata. Waits out rate limits. Resolves to "UNAUTHORIZED" if Discord no longer accepts the access token.
export async function putRoleConnection({ accessToken, platformUsername, metadata, }: { accessToken: string; platformUsername: string; metadata: SendouInkDiscordMetadata; }): Promise<"OK" | "UNAUTHORIZED">