mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-12 02:47:28 -05:00
feat: implement discord oauth flow
This commit is contained in:
23
server/api/account/discord-link.get.ts
Normal file
23
server/api/account/discord-link.get.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useDiscord } from "~~/server/utils/discord";
|
||||
import { ApiAccountDiscordLink } from "~~/shared/api-types";
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAccountDiscordLink> => {
|
||||
enforceLoggedIn(event);
|
||||
const discord = useDiscord(event);
|
||||
if (!discord) throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured',
|
||||
})
|
||||
|
||||
const redirectUrl = discord.makeCallbackUrl();
|
||||
const url = new URL("https://discord.com/oauth2/authorize");
|
||||
url.searchParams.set('response_type', 'code');
|
||||
url.searchParams.set('client_id', 'code');
|
||||
url.searchParams.set('scope', 'identify');
|
||||
url.searchParams.set('redirect_uri', redirectUrl);
|
||||
url.searchParams.set('prompt', 'scope');
|
||||
url.searchParams.set('integration_type', '1');
|
||||
return {
|
||||
url: url.toString(),
|
||||
}
|
||||
});
|
||||
15
server/api/account/discord-unlink.post.ts
Normal file
15
server/api/account/discord-unlink.post.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const auth = enforceLoggedIn(event);
|
||||
const discord = useDiscord(event);
|
||||
if (!discord) throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured',
|
||||
})
|
||||
|
||||
const grpc = useApiGrpcWithToken(event, auth.token);
|
||||
await grpc.setDiscordConnectionData({
|
||||
id: '',
|
||||
});
|
||||
|
||||
// TODO set roles based on stripe info
|
||||
});
|
||||
Reference in New Issue
Block a user