🚸 (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:
@@ -60,15 +60,20 @@ export const SignInForm = ({
|
|||||||
const handleEmailSubmit = async (e: FormEvent) => {
|
const handleEmailSubmit = async (e: FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setAuthLoading(true)
|
setAuthLoading(true)
|
||||||
await signIn('email', {
|
const response = await signIn('email', {
|
||||||
email: emailValue,
|
email: emailValue,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
})
|
})
|
||||||
showToast({
|
response?.error
|
||||||
status: 'success',
|
? showToast({
|
||||||
title: 'Success!',
|
title: 'Unauthorized',
|
||||||
description: 'Check your inbox to sign in',
|
description: 'Sign ups are disabled.',
|
||||||
})
|
})
|
||||||
|
: showToast({
|
||||||
|
status: 'success',
|
||||||
|
title: 'Success!',
|
||||||
|
description: 'Check your inbox to sign in',
|
||||||
|
})
|
||||||
setAuthLoading(false)
|
setAuthLoading(false)
|
||||||
}
|
}
|
||||||
if (isLoadingProviders) return <Spinner />
|
if (isLoadingProviders) return <Spinner />
|
||||||
|
|||||||
@@ -127,8 +127,10 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
user: userFromDb,
|
user: userFromDb,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
signIn: async ({ account }) => {
|
signIn: async ({ account, user }) => {
|
||||||
if (!account) return false
|
const userExists = user?.graphNavigation !== undefined
|
||||||
|
if (!account || (process.env.DISABLE_SIGNUP === 'true' && !userExists))
|
||||||
|
return false
|
||||||
const requiredGroups = getRequiredGroups(account.provider)
|
const requiredGroups = getRequiredGroups(account.provider)
|
||||||
if (requiredGroups.length > 0) {
|
if (requiredGroups.length > 0) {
|
||||||
const userGroups = await getUserGroups(account)
|
const userGroups = await getUserGroups(account)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"main": "./index.ts",
|
"main": "./index.ts",
|
||||||
"types": "./index.ts",
|
"types": "./index.ts",
|
||||||
"scripts": {
|
"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",
|
"build": "pnpm generate:schema",
|
||||||
"start:sutdio": "dotenv -e ../../apps/builder/.env.local -v BROWSER=none prisma studio",
|
"start:sutdio": "dotenv -e ../../apps/builder/.env.local -v BROWSER=none prisma studio",
|
||||||
"generate:schema": "dotenv -e ../../apps/builder/.env.local prisma generate",
|
"generate:schema": "dotenv -e ../../apps/builder/.env.local prisma generate",
|
||||||
|
|||||||
Reference in New Issue
Block a user