Skip to content

Commit

Permalink
feat: Moved custom callback url outside, therefore devs needs to spec…
Browse files Browse the repository at this point in the history
…ify `PROVIDER_ID` if they need it.
  • Loading branch information
red-game-dev committed Nov 16, 2023
1 parent 28ba964 commit efe0327
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4,842 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ storybook-static

.env
vite-env.d.ts
stats.html
stats.*
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
}
```

### 🔹 Custom Next Auth URL for Provider

If you would like to customize your callback URL as `/steam` or some other route, you can easily do so as below.

```ts
// app/api/auth/[...nextauth]/route.ts
import { PROVIDER_ID } from '@hyperplay/next-auth-steam'

// ...

async function handler(
req: NextRequest,
ctx: {
params: {
nextauth: string[]
}
}
) {
// @ts-ignore
return NextAuth(req, ctx, {
providers: [
SteamProvider({
clientSecret: process.env.STEAM_SECRET!
nextAuthUrl: `${process.env.NEXTAUTH_URL!}/${PROVIDER_ID}` // https://example.com/api/auth/callback/steam
})
]
})
}

export { handler as GET, handler as POST }
```

### 🔹 App Directory Integration

```ts
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperplay/next-auth-steam",
"version": "0.1.7",
"version": "0.1.8",
"license": "BUSL-1.1",
"description": "Steam authentication provider for next-auth",
"main": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export function Steam(
providerOptions: SteamProviderOptions
): OAuthConfig<SteamProfile> {
const {
nextAuthUrl = 'http://localhost:3000',
nextAuthUrl = 'http://localhost:3000/api/auth/callback',
clientSecret,
...options
} = providerOptions

const callbackUrl = new URL(nextAuthUrl)

const realm = callbackUrl.origin
const returnTo = `${callbackUrl.href}/api/auth/callback/${PROVIDER_ID}`
const returnTo = callbackUrl.href
const path = `${callbackUrl.pathname}${callbackUrl.search}`

return {
Expand Down
Loading

0 comments on commit efe0327

Please sign in to comment.