fix: Cannot use Discord authentication if guild name looks like a URL, closes #7776

This commit is contained in:
Tom Moor
2024-11-02 13:40:11 -04:00
parent 0e249951ab
commit d87e1f6264

View File

@@ -1,4 +1,5 @@
import passport from "@outlinewiki/koa-passport";
import { isURL } from "class-validator";
import type {
RESTGetAPICurrentUserGuildsResult,
RESTGetAPICurrentUserResult,
@@ -129,10 +130,19 @@ if (env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET) {
}
}
/** Guild Name */
teamName = guild.name;
subdomain = slugify(guild.name);
/** If the guild name is a URL, use the subdomain instead we do not allow URLs in names. */
if (
isURL(teamName, {
require_host: false,
require_protocol: false,
})
) {
teamName = subdomain;
}
/** Fetch the user's member object in the server for nickname and roles */
const guildMember: RESTGetCurrentUserGuildMemberResult =
await request(