mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 04:19:26 +00:00
58 lines
2.0 KiB
Plaintext
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>
|