2
0

🚸 (signin) Better disabled signups behavior

If DISABLE_SIGNUP is set to "true" will directly see a clear error message

Closes #111
This commit is contained in:
Baptiste Arnaud
2022-11-03 08:13:22 +01:00
parent 3747f688c5
commit 570a780db1
3 changed files with 16 additions and 9 deletions

View File

@ -60,15 +60,20 @@ export const SignInForm = ({
const handleEmailSubmit = async (e: FormEvent) => {
e.preventDefault()
setAuthLoading(true)
await signIn('email', {
const response = await signIn('email', {
email: emailValue,
redirect: false,
})
showToast({
status: 'success',
title: 'Success!',
description: 'Check your inbox to sign in',
})
response?.error
? showToast({
title: 'Unauthorized',
description: 'Sign ups are disabled.',
})
: showToast({
status: 'success',
title: 'Success!',
description: 'Check your inbox to sign in',
})
setAuthLoading(false)
}
if (isLoadingProviders) return <Spinner />

View File

@ -127,8 +127,10 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
user: userFromDb,
}
},
signIn: async ({ account }) => {
if (!account) return false
signIn: async ({ account, user }) => {
const userExists = user?.graphNavigation !== undefined
if (!account || (process.env.DISABLE_SIGNUP === 'true' && !userExists))
return false
const requiredGroups = getRequiredGroups(account.provider)
if (requiredGroups.length > 0) {
const userGroups = await getUserGroups(account)

View File

@ -5,7 +5,7 @@
"main": "./index.ts",
"types": "./index.ts",
"scripts": {
"dev": "dotenv -e ../../apps/builder/.env.local prisma db push && pnpm generate:schema",
"dev": "dotenv -e ../../apps/builder/.env.local prisma db push && pnpm generate:schema && pnpm start:sutdio",
"build": "pnpm generate:schema",
"start:sutdio": "dotenv -e ../../apps/builder/.env.local -v BROWSER=none prisma studio",
"generate:schema": "dotenv -e ../../apps/builder/.env.local prisma generate",