From 3b027e858fe7cb3d9753abf4f4052dd4a518bfd9 Mon Sep 17 00:00:00 2001 From: pilcrowOnPaper <80624252+pilcrowOnPaper@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:05:19 +0900 Subject: [PATCH] Fix broken code in account linking guide (#959) --- .../guidebook/oauth-account-linking/index.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/documentation/content/guidebook/oauth-account-linking/index.md b/documentation/content/guidebook/oauth-account-linking/index.md index da3e2c093..992367180 100644 --- a/documentation/content/guidebook/oauth-account-linking/index.md +++ b/documentation/content/guidebook/oauth-account-linking/index.md @@ -10,13 +10,17 @@ When providing more than one ways to sign in, you may want to link multiple prov Here's a basic OAuth implementation using the official integration. ```ts -const { existingUser, createUser, providerUser } = validateCallback(code); +const { existingUser, createUser, providerUser } = + providerAuth.validateCallback(code); const getUser = async () => { if (existingUser) return existingUser; + if (!providerUser.email_verified) { + throw new Error("Email not verified"); + } return await createUser({ attributes: { - email: providerUser.email + email: await getGithubUserEmail(githubUser) } }); }; @@ -36,7 +40,7 @@ It's important to note `existingUser` is defined if a user linked to the provide import { auth } from "./lucia.js"; const { existingUser, createUser, providerUser, createKey } = - validateCallback(code); + providerAuth.validateCallback(code); const getUser = async () => { if (existingUser) return existingUser; @@ -46,11 +50,11 @@ const getUser = async () => { const existingDatabaseUserWithEmail = await db.getUserByEmail( providerUser.email ); - if (existingUserWithEmail) { + if (existingDatabaseUserWithEmail) { // transform `UserSchema` to `User` const user = auth.transformDatabaseUser(existingDatabaseUserWithEmail); await createKey(user.userId); - return auth.transformDatabaseUser(existingUserWithEmail); + return user; } return await createUser({ attributes: { @@ -58,4 +62,8 @@ const getUser = async () => { } }); }; + +const user = await getUser(); + +// create session and sign in ```