Remove auth gateway code

This commit is contained in:
Kalle
2025-04-16 12:32:04 +03:00
parent b77f70a22d
commit 087a188133
2 changed files with 4 additions and 18 deletions

View File

@@ -5,8 +5,6 @@ SESSION_SECRET=secret
// Auth https://discord.com/developers
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
AUTH_GATEWAY_PROFILE_URL=
AUTH_GATEWAY_TOKEN_URL=
// Patreon integration https://www.patreon.com/portal/registration/register-clients
PATREON_ACCESS_TOKEN=

View File

@@ -29,10 +29,6 @@ const discordUserDetailsSchema = z.tuple([
export const DiscordStrategy = () => {
const envVars = authEnvVars();
const authGatewayEnabled = () => {
return Boolean(process.env.AUTH_GATEWAY_TOKEN_URL);
};
const jsonIfOk = (res: Response) => {
if (!res.ok) {
throw new Error(
@@ -56,30 +52,22 @@ export const DiscordStrategy = () => {
]);
};
const fetchProfileViaGateway = (token: string) => {
const url = `${process.env.AUTH_GATEWAY_PROFILE_URL}?token=${token}`;
return fetch(url).then(jsonIfOk);
};
return new OAuth2Strategy(
{
clientId: envVars.DISCORD_CLIENT_ID,
clientSecret: envVars.DISCORD_CLIENT_SECRET,
authorizationEndpoint: "https://discord.com/api/oauth2/authorize",
tokenEndpoint:
process.env.AUTH_GATEWAY_TOKEN_URL ||
"https://discord.com/api/oauth2/token",
tokenEndpoint: "https://discord.com/api/oauth2/token",
redirectURI: new URL("/auth/callback", envVars.BASE_URL).toString(),
scopes: ["identify", "connections", "email"],
},
async ({ tokens }) => {
try {
const discordResponses = authGatewayEnabled()
? await fetchProfileViaGateway(tokens.accessToken())
: await fetchProfileViaDiscordApi(tokens.accessToken());
const discordResponses = await fetchProfileViaDiscordApi(
tokens.accessToken(),
);
const [user, connections] =
discordUserDetailsSchema.parse(discordResponses);