Skip to content

Commit 6b10529

Browse files
feat: block Gmail/Googlemail email+password sign-up, prompt Google OAuth (#343)
1 parent e308594 commit 6b10529

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/app/(auth)/sign-up/page.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { AuthFormMessage, type AuthMessage } from '@/features/auth/form-message'
1717
import { OAuthProviders } from '@/features/auth/oauth-provider-buttons'
1818
import { TurnstileWidget } from '@/features/auth/turnstile-widget'
1919
import { useTurnstile } from '@/features/auth/use-turnstile'
20+
import { isGoogleEmail } from '@/lib/utils/email'
2021
import { Button } from '@/ui/primitives/button'
2122
import {
2223
Form,
@@ -84,6 +85,9 @@ export default function SignUp() {
8485
}
8586
}, [searchParams, form])
8687

88+
const emailValue = form.watch('email')
89+
const isGoogleSignUp = emailValue ? isGoogleEmail(emailValue) : false
90+
8791
useEffect(() => {
8892
if (message && 'success' in message && message.success) {
8993
const timer = setTimeout(
@@ -179,10 +183,22 @@ export default function SignUp() {
179183
className="my-1"
180184
/>
181185

186+
{isGoogleSignUp && (
187+
<AuthFormMessage
188+
className="mt-2"
189+
message={{
190+
message: USER_MESSAGES.signUpGoogleEmail.message,
191+
}}
192+
/>
193+
)}
194+
182195
<Button
183196
type="submit"
184197
loading={isExecuting ? 'Signing up...' : undefined}
185-
disabled={CAPTCHA_REQUIRED_CLIENT && !turnstile.captchaToken}
198+
disabled={
199+
isGoogleSignUp ||
200+
(CAPTCHA_REQUIRED_CLIENT && !turnstile.captchaToken)
201+
}
186202
>
187203
Sign up
188204
</Button>

src/configs/user-messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export const USER_MESSAGES = {
8484
captchaFailed: {
8585
message: 'Captcha verification failed. Please try again.',
8686
},
87+
signUpGoogleEmail: {
88+
message:
89+
'Please use "Continue with Google" above to sign up with your Google account.',
90+
},
8791
}
8892

8993
export const getTimeoutMsFromUserMessage = (

src/core/server/actions/auth-actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { l, serializeErrorForLog } from '@/core/shared/clients/logger/logger'
2424
import { relativeUrlSchema } from '@/core/shared/schemas/url'
2525
import { verifyTurnstileToken } from '@/lib/captcha/turnstile'
2626
import { encodedRedirect } from '@/lib/utils/auth'
27+
import { isGoogleEmail } from '@/lib/utils/email'
2728

2829
async function validateCaptcha(captchaToken: string | undefined) {
2930
if (!CAPTCHA_REQUIRED_SERVER) {
@@ -203,6 +204,10 @@ export const signUpAction = actionClient
203204
const ip =
204205
headerStore.get('x-forwarded-for')?.split(',')[0]?.trim() ?? undefined
205206

207+
if (isGoogleEmail(email)) {
208+
return returnServerError(USER_MESSAGES.signUpGoogleEmail.message)
209+
}
210+
206211
// basic security check, that password does not equal e-mail
207212
if (password && email && password.toLowerCase() === email.toLowerCase()) {
208213
return returnValidationErrors(signUpSchema, {

src/lib/utils/email.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const GOOGLE_EMAIL_DOMAINS = ['gmail.com', 'googlemail.com']
2+
3+
export function isGoogleEmail(email: string): boolean {
4+
const domain = email.split('@').pop()?.toLowerCase()
5+
return domain !== undefined && GOOGLE_EMAIL_DOMAINS.includes(domain)
6+
}

0 commit comments

Comments
 (0)