Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
project_ss23_gameunity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Yusuf Akgül
project_ss23_gameunity
Commits
3580bb38
Commit
3580bb38
authored
1 year ago
by
Yusuf Akgül
Browse files
Options
Downloads
Patches
Plain Diff
validation additions for not existing user in signup
parent
09cbfbc4
No related branches found
No related tags found
1 merge request
!20
validation additions for not existing user in signup
Pipeline
#36473
failed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/user-auth-form.tsx
+18
-3
18 additions, 3 deletions
components/user-auth-form.tsx
lib/auth.ts
+2
-2
2 additions, 2 deletions
lib/auth.ts
with
20 additions
and
5 deletions
components/user-auth-form.tsx
+
18
−
3
View file @
3580bb38
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
zodResolver
}
from
"
@hookform/resolvers/zod
"
import
{
zodResolver
}
from
"
@hookform/resolvers/zod
"
import
{
signIn
}
from
'
next-auth/react
'
import
{
signIn
}
from
'
next-auth/react
'
import
{
useSearchParams
}
from
"
next/navigation
"
import
{
useRouter
,
useSearchParams
}
from
"
next/navigation
"
import
{
HTMLAttributes
,
useState
}
from
'
react
'
import
{
HTMLAttributes
,
useState
}
from
'
react
'
import
{
useForm
}
from
'
react-hook-form
'
import
{
useForm
}
from
'
react-hook-form
'
import
*
as
z
from
"
zod
"
import
*
as
z
from
"
zod
"
...
@@ -33,6 +33,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
...
@@ -33,6 +33,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
})
})
const
[
isLoading
,
setIsLoading
]
=
useState
<
boolean
>
(
false
)
const
[
isLoading
,
setIsLoading
]
=
useState
<
boolean
>
(
false
)
const
[
isGitHubLoading
,
setIsGitHubLoading
]
=
useState
<
boolean
>
(
false
)
const
[
isGitHubLoading
,
setIsGitHubLoading
]
=
useState
<
boolean
>
(
false
)
const
router
=
useRouter
();
const
searchParams
=
useSearchParams
()
const
searchParams
=
useSearchParams
()
async
function
onSubmit
(
data
:
FormData
)
{
async
function
onSubmit
(
data
:
FormData
)
{
...
@@ -68,13 +69,25 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
...
@@ -68,13 +69,25 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
const
signInResult
=
await
signIn
(
"
credentials
"
,
{
const
signInResult
=
await
signIn
(
"
credentials
"
,
{
usernameOrEmail
:
data
.
email
?.
toLowerCase
()
||
data
.
usernameOrEmail
?.
toLowerCase
(),
usernameOrEmail
:
data
.
email
?.
toLowerCase
()
||
data
.
usernameOrEmail
?.
toLowerCase
(),
password
:
data
.
password
,
password
:
data
.
password
,
redirect
:
tru
e
,
redirect
:
fals
e
,
callbackUrl
:
searchParams
?.
get
(
"
from
"
)
||
"
/home
"
,
callbackUrl
:
searchParams
?.
get
(
"
from
"
)
||
"
/home
"
,
});
});
setIsLoading
(
false
)
setIsLoading
(
false
)
if
(
signInResult
?.
error
)
{
if
(
signInResult
?.
error
)
{
if
(
signInResult
.
error
===
"
user not found
"
)
{
setError
(
'
usernameOrEmail
'
,
{
type
:
'
manual
'
,
message
:
'
Sorry, we couldn
\'
t find an account with the provided email / username. Please double-check your input or create a new account.
'
});
}
if
(
signInResult
.
error
===
"
invalid password
"
)
{
setError
(
'
password
'
,
{
type
:
'
manual
'
,
message
:
'
Sorry, but it seems like the password you entered is invalid. Please try again.
'
});
}
return
toast
({
return
toast
({
variant
:
"
destructive
"
,
variant
:
"
destructive
"
,
title
:
"
Uh oh! Something went wrong.
"
,
title
:
"
Uh oh! Something went wrong.
"
,
...
@@ -83,6 +96,8 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
...
@@ -83,6 +96,8 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
})
})
}
}
router
.
push
(
"
/home
"
)
if
(
type
===
"
signup
"
)
{
if
(
type
===
"
signup
"
)
{
return
toast
({
return
toast
({
title
:
"
Congratulations!
"
,
title
:
"
Congratulations!
"
,
...
@@ -90,7 +105,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
...
@@ -90,7 +105,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
})
})
}
else
{
}
else
{
return
toast
({
return
toast
({
title
:
"
Log
g
in
g in
.
"
,
title
:
"
Login
successful
.
"
,
description
:
"
You will be redirected shortly.
"
,
description
:
"
You will be redirected shortly.
"
,
})
})
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/auth.ts
+
2
−
2
View file @
3580bb38
...
@@ -42,7 +42,7 @@ export const authOptions: NextAuthOptions = {
...
@@ -42,7 +42,7 @@ export const authOptions: NextAuthOptions = {
});
});
if
(
!
user
||
!
user
.
password
)
{
if
(
!
user
||
!
user
.
password
)
{
return
null
throw
new
Error
(
'
user not found
'
)
}
}
const
isPasswordValid
=
await
compare
(
const
isPasswordValid
=
await
compare
(
...
@@ -51,7 +51,7 @@ export const authOptions: NextAuthOptions = {
...
@@ -51,7 +51,7 @@ export const authOptions: NextAuthOptions = {
)
)
if
(
!
isPasswordValid
)
{
if
(
!
isPasswordValid
)
{
return
null
throw
new
Error
(
'
invalid password
'
)
}
}
return
{
return
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment