Skip to content

Commit

Permalink
Fix broken code in account linking guide (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper authored Aug 11, 2023
1 parent 6fb45ca commit 3b027e8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions documentation/content/guidebook/oauth-account-linking/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});
};
Expand All @@ -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;
Expand All @@ -46,16 +50,20 @@ 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: {
email: providerUser.email
}
});
};

const user = await getUser();

// create session and sign in
```

0 comments on commit 3b027e8

Please sign in to comment.