[GH-ISSUE #2731] Signing in using generic OAuth requires email verification #9324

Closed
opened 2026-04-13 04:45:36 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @ronnyandre on GitHub (May 21, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2731

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When I sign up using my company's Okta as generic Oauth provider, I get the "verify email" message that I implemented for regular email signup. Is there a way to automatically verify the user if he or she signs in with Okta? (In our Okta the application is manually assigned to each user before they can log in, thus being automatically verified).

Current vs. Expected behavior

I would assume the email was verified when you signed in using generic OAuth, the same way when signing up with Gmail or Github etc.

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: macOS 15.4.1
- NextJS 15.3.2
- Node 23.11.0

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "sqlite",
    }),
    emailAndPassword: {
        enabled: true,
        autoSignIn: false,
        requireEmailVerification: true,
        sendResetPassword: async ({ user, url }) => {
            await sendEmailAction({
                to: user.email,
                subject: "Reset your password",
                meta: {
                    description:
                        "Please click the link below to reset your password.",
                    link: url,
                },
            });
        },
    },
    emailVerification: {
        sendOnSignUp: true,
        autoSignInAfterVerification: true,
        sendVerificationEmail: async ({ user, url }) => {
            const link = new URL(url);
            link.searchParams.set("callbackURL", "/verify");

            await sendEmailAction({
                to: user.email,
                subject: "Verify your email address",
                meta: {
                    description:
                        "Please verify your email address to complete registration",
                    link: String(link),
                },
            });
        },
    },
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID as string,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
        },
        github: {
            clientId: process.env.GITHUB_CLIENT_ID as string,
            clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
        },
    },
    plugins: [
        nextCookies(),
        genericOAuth({
            config: [
                {
                    providerId: "okta",
                    clientId: process.env.OKTA_CLIENT_ID as string,
                    clientSecret: process.env.OKTA_CLIENT_SECRET as string,
                    scopes: ["openid", "email", "profile"],
                    discoveryUrl:
                        "[REDACTED]",
                },
            ],
        }),
    ]
});

Additional context

No response

Originally created by @ronnyandre on GitHub (May 21, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2731 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When I sign up using my company's Okta as generic Oauth provider, I get the "verify email" message that I implemented for regular email signup. Is there a way to automatically verify the user if he or she signs in with Okta? (In our Okta the application is manually assigned to each user before they can log in, thus being automatically verified). ### Current vs. Expected behavior I would assume the email was verified when you signed in using generic OAuth, the same way when signing up with Gmail or Github etc. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: macOS 15.4.1 - NextJS 15.3.2 - Node 23.11.0 ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "sqlite", }), emailAndPassword: { enabled: true, autoSignIn: false, requireEmailVerification: true, sendResetPassword: async ({ user, url }) => { await sendEmailAction({ to: user.email, subject: "Reset your password", meta: { description: "Please click the link below to reset your password.", link: url, }, }); }, }, emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user, url }) => { const link = new URL(url); link.searchParams.set("callbackURL", "/verify"); await sendEmailAction({ to: user.email, subject: "Verify your email address", meta: { description: "Please verify your email address to complete registration", link: String(link), }, }); }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, github: { clientId: process.env.GITHUB_CLIENT_ID as string, clientSecret: process.env.GITHUB_CLIENT_SECRET as string, }, }, plugins: [ nextCookies(), genericOAuth({ config: [ { providerId: "okta", clientId: process.env.OKTA_CLIENT_ID as string, clientSecret: process.env.OKTA_CLIENT_SECRET as string, scopes: ["openid", "email", "profile"], discoveryUrl: "[REDACTED]", }, ], }), ] }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:45:36 -05:00
Author
Owner

@gee1k commented on GitHub (May 22, 2025):

You can rewrite emailVerified through mapProfileToUser.

genericOAuth({
   config: [
       {
           providerId: "okta",
           clientId: process.env.OKTA_CLIENT_ID as string,
           clientSecret: process.env.OKTA_CLIENT_SECRET as string,
           scopes: ["openid", "email", "profile"],
           discoveryUrl: "[REDACTED]",
           mapProfileToUser: (profile) => {
           return {
               ...profile,
               emailVerified: true
           }
       }
       },
   ],
})
<!-- gh-comment-id:2900612792 --> @gee1k commented on GitHub (May 22, 2025): You can rewrite emailVerified through mapProfileToUser. ```ts genericOAuth({ config: [ { providerId: "okta", clientId: process.env.OKTA_CLIENT_ID as string, clientSecret: process.env.OKTA_CLIENT_SECRET as string, scopes: ["openid", "email", "profile"], discoveryUrl: "[REDACTED]", mapProfileToUser: (profile) => { return { ...profile, emailVerified: true } } }, ], }) ```
Author
Owner

@ronnyandre commented on GitHub (May 22, 2025):

Thanks, I didn't think of that!

<!-- gh-comment-id:2901005988 --> @ronnyandre commented on GitHub (May 22, 2025): Thanks, I didn't think of that!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9324