Skip to content

Commit 5066726

Browse files
feat(providers): refactor Cognito provider (#2829)
* chore(dev): add CognitoProvider to dev app * feat(log): log `error_description` in OAuth callback * fix(providers): migrate Cognito to v4 * docs: mention superblog.ai for infra support * fix: return profile picture for Cognito * fix(ts): add picture to CognitoProfile
1 parent ffa2b1b commit 5066726

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ We're happy to announce we've recently created an [OpenCollective](https://openc
197197
<div>Checkly</div><br />
198198
<sub>☁️ Infrastructure Support</sub>
199199
</td>
200+
<td align="center" valign="top">
201+
<a href="https://superblog.ai/" target="_blank">
202+
<img width="128px" src="https://d33wubrfki0l68.cloudfront.net/cdc4a3833bd878933fcc131655878dbf226ac1c5/10cd6/images/logo_bolt_small.png" alt="superblog Logo" />
203+
</a><br />
204+
<div>superblog</div><br />
205+
<sub>☁️ Infrastructure Support</sub>
206+
</td>
200207
</tr><tr></tr>
201208
</tbody>
202209
</table>

app/pages/api/auth/[...nextauth].ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import MailchimpProvider from "next-auth/providers/mailchimp"
1919
import DiscordProvider from "next-auth/providers/discord"
2020
import AzureADProvider from "next-auth/providers/azure-ad"
2121
import SpotifyProvider from "next-auth/providers/spotify"
22+
import CognitoProvider from "next-auth/providers/cognito"
2223

2324
// import { PrismaAdapter } from "@next-auth/prisma-adapter"
2425
// import { PrismaClient } from "@prisma/client"
@@ -143,6 +144,11 @@ export default NextAuth({
143144
clientId: process.env.SPOTIFY_ID,
144145
clientSecret: process.env.SPOTIFY_SECRET,
145146
}),
147+
CognitoProvider({
148+
clientId: process.env.COGNITO_ID,
149+
clientSecret: process.env.COGNITO_SECRET,
150+
issuer: process.env.COGNITO_ISSUER,
151+
}),
146152
],
147153
jwt: {
148154
encryption: true,

src/providers/cognito.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/providers/cognito.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { OAuthConfig, OAuthUserConfig } from "."
2+
3+
export interface CognitoProfile {
4+
sub: string
5+
name: string
6+
email: string
7+
picture: string
8+
}
9+
10+
export default function Cognito<P extends Record<string, any> = CognitoProfile>(
11+
options: OAuthUserConfig<P>
12+
): OAuthConfig<P> {
13+
return {
14+
id: "cognito",
15+
name: "Cognito",
16+
type: "oauth",
17+
wellKnown: `${options.issuer}/.well-known/openid-configuration`,
18+
profile(profile) {
19+
return {
20+
id: profile.sub,
21+
name: profile.name,
22+
email: profile.email,
23+
image: profile.picture,
24+
}
25+
},
26+
options,
27+
}
28+
}

src/server/lib/oauth/callback.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default async function oAuthCallback(
2121
const error = new Error(errorMessage)
2222
logger.error("OAUTH_CALLBACK_HANDLER_ERROR", {
2323
error,
24+
error_description: req.query?.error_description,
2425
body: req.body,
2526
providerId: provider.id,
2627
})

0 commit comments

Comments
 (0)