const discord = new Discord(env.clientId, env.clientSecret, env.redirectUri);
const state = generateState();
const url = await discord.createAuthorizationURL(state, {
scopes: ["identify"],
});
return new Response(null, {
status: 302,
headers: {
Location: url.toString(),
"Set-Cookie": serializeCookie("discord_oauth_state", state, {
httpOnly: true,
secure: process.env.NODE_ENV === "production", // set `Secure` flag in HTTPS
maxAge: 60 * 10, // 10 minutes
path: "/"
})
}
});
};
import { Button } from "@mantine/core";
import { discordSignin } from "./actions";
export function DiscordOAuth() {
return (
<form action={discordSignin}>
<Button type="submit">Sign in with Discord</Button>
</form>
);
}
how do i use server actions to perform a redirect while setting headers?