Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linked accounts to account page (#3489)
Does not look the best, but we should add buttons for users to unlink their accounts (or link more)
- Loading branch information
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { withoutRole } from "src/lib/auth"; | ||
import prisma from "src/lib/prismadb"; | ||
import { ExternalProvider, UserAccountResponse } from "src/types/Account"; | ||
|
||
const handler = withoutRole("banned", async (req, res, token) => { | ||
const user = await prisma.user.findFirst({ | ||
where: { id: token.sub }, | ||
select: { emailVerified: true, accounts: true }, | ||
}); | ||
|
||
const emailIsVerified = Boolean(user.emailVerified); | ||
const accounts = user.accounts.map(({ provider, providerAccountId }) => ({ | ||
provider: provider as ExternalProvider, | ||
providerAccountId, | ||
})); | ||
|
||
const response: UserAccountResponse = { emailIsVerified, accounts }; | ||
|
||
return res.status(200).json(response); | ||
}); | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type ExternalProvider = "google" | "discord"; | ||
|
||
export interface UserAccountResponse { | ||
emailIsVerified: boolean; | ||
accounts: Array<{ provider: ExternalProvider; providerAccountId: string }>; | ||
} |