Files
better-auth/docs/content/docs/authentication/discord.mdx
2024-09-23 23:19:22 +03:00

58 lines
2.0 KiB
Plaintext

---
title: Discord
description: Discord Provider
---
<Steps>
<Step>
### Get your Discord credentials
To use Discord sign in, you need a client ID and client secret. You can get them from the [Discord Developer Portal](https://discord.com/developers/applications).
</Step>
<Step>
### Configure the provider
To configure the provider, you need to import the provider and pass it to the `socialProvider` option of the auth instance.
```ts title="auth.ts" twoslash
const process = {
env: {
DISCORD_CLIENT_ID: "" as string,
DISCORD_CLIENT_SECRET: "" as string,
}
}
// ---cut---
import { betterAuth } from "better-auth"
import { discord } from "better-auth/social-providers"
export const auth = await betterAuth({
database: {
provider: "sqlite",
url: "./db.sqlite",
},
socialProvider: { // [!code highlight]
discord: { // [!code highlight]
clientId: process.env.DISCORD_CLIENT_ID as string, // [!code highlight]
clientSecret: process.env.DISCORD_CLIENT_SECRET as string, // [!code highlight]
}, // [!code highlight]
}, // [!code highlight]
})
```
</Step>
<Step>
### Signin with Discord
To signin with Discord, you can use the `signIn.social` function provided by the client. The `signIn` function takes an object with the following properties:
- `provider`: The provider to use. It should be set to `discord`.
```ts title="client.ts" twoslash /
import { createAuthClient } from "better-auth/client"
const client = createAuthClient()
const signin = async () => {
const data = await client.signIn.social({
provider: "discord"
})
}
```
</Step>
</Steps>