mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
58 lines
2.1 KiB
Plaintext
58 lines
2.1 KiB
Plaintext
---
|
|
title: Apple
|
|
description: Apple
|
|
---
|
|
|
|
<Steps>
|
|
<Step>
|
|
### Get your OAuth credentials
|
|
To use Apple sign in, you need a client ID and client secret. You can get them from the [Apple Developer Portal](https://developer.apple.com/account/resources/authkeys/list).
|
|
|
|
Apple requires a little harder setup to get a client secret. You can use the guide below to get your client secret.
|
|
<Link href="https://developer.apple.com/documentation/accountorganizationaldatasharing/creating-a-client-secret">
|
|
Creating a client secret
|
|
</Link>
|
|
</Step>
|
|
<Step>
|
|
### Configure the provider
|
|
To configure the provider, you need to import the provider and pass it to the `socialProviders` option of the auth instance.
|
|
|
|
```ts title="auth.ts"
|
|
const process = {
|
|
env: {
|
|
APPLE_CLIENT_ID: "" as string,
|
|
APPLE_CLIENT_SECRET: "" as string,
|
|
}
|
|
}
|
|
// ---cut---
|
|
import { betterAuth } from "better-auth"
|
|
import { apple } from "better-auth/social-providers"
|
|
|
|
export const auth = await betterAuth({
|
|
socialProviders: { // [!code highlight]
|
|
apple({ // [!code highlight]
|
|
clientId: process.env.APPLE_CLIENT_ID as string, // [!code highlight]
|
|
clientSecret: process.env.APPLE_CLIENT_SECRET as string, // [!code highlight]
|
|
}), // [!code highlight]
|
|
}, // [!code highlight]
|
|
})
|
|
```
|
|
</Step>
|
|
<Step>
|
|
### Signin with Apple
|
|
To signin with Apple, 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 `apple`.
|
|
|
|
```ts title="client.ts" /
|
|
import { createAuthClient } from "better-auth/client"
|
|
const client = createAuthClient()
|
|
|
|
const signin = async () => {
|
|
const data = await client.signIn.social({
|
|
provider: "apple"
|
|
})
|
|
}
|
|
```
|
|
</Step>
|
|
</Steps>
|