mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-15 07:17:00 +10:00
Fix GitHub OAuth login for migrated users (#2620)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
@@ -60,7 +60,7 @@ export function UserDropdownMenu({ children }: Props) {
|
||||
});
|
||||
}
|
||||
|
||||
if (!session) return null;
|
||||
if (!session?.user) return null;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BetterAuthError } from "@better-auth/core/error";
|
||||
import { and, eq, or } from "drizzle-orm";
|
||||
import { passkey } from "@better-auth/passkey";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { betterAuth } from "better-auth/minimal";
|
||||
@@ -161,12 +162,44 @@ const getAuthConfig = () => {
|
||||
// biome-ignore lint/style/noNonNullAssertion: enabled check ensures these are not null
|
||||
clientSecret: env.GITHUB_CLIENT_SECRET!,
|
||||
mapProfileToUser: async (profile) => {
|
||||
const login = profile.login ?? String(profile.id);
|
||||
const normalizedLogin = toUsername(login);
|
||||
const [legacyAccount] = await db
|
||||
.select({
|
||||
accountId: schema.account.accountId,
|
||||
email: schema.user.email,
|
||||
emailVerified: schema.user.emailVerified,
|
||||
username: schema.user.username,
|
||||
displayUsername: schema.user.displayUsername,
|
||||
})
|
||||
.from(schema.account)
|
||||
.innerJoin(schema.user, eq(schema.account.userId, schema.user.id))
|
||||
.where(
|
||||
and(
|
||||
eq(schema.account.providerId, "github"),
|
||||
or(eq(schema.user.username, normalizedLogin), eq(schema.user.displayUsername, login)),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (legacyAccount) {
|
||||
return {
|
||||
id: legacyAccount.accountId,
|
||||
name: profile.name,
|
||||
email: legacyAccount.email,
|
||||
image: profile.avatar_url,
|
||||
username: legacyAccount.username,
|
||||
displayUsername: legacyAccount.displayUsername,
|
||||
emailVerified: legacyAccount.emailVerified,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
image: profile.avatar_url,
|
||||
username: profile.login,
|
||||
displayUsername: profile.login,
|
||||
username: normalizedLogin,
|
||||
displayUsername: login,
|
||||
emailVerified: true,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user