Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COM3014
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abdelsamad, Mouaz R (UG - SISC)
COM3014
Commits
b4c37340
Commit
b4c37340
authored
11 months ago
by
lcross2002
Browse files
Options
Downloads
Patches
Plain Diff
fix login infinite loop bug
parent
6da3dcad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
UserMicroservice/Controllers/UserController.cs
+1
-1
1 addition, 1 deletion
UserMicroservice/Controllers/UserController.cs
client/src/components/Login/Login.tsx
+8
-4
8 additions, 4 deletions
client/src/components/Login/Login.tsx
client/src/helpers/Api.ts
+10
-2
10 additions, 2 deletions
client/src/helpers/Api.ts
with
19 additions
and
7 deletions
UserMicroservice/Controllers/UserController.cs
+
1
−
1
View file @
b4c37340
...
...
@@ -47,7 +47,7 @@ namespace UserMicroservice.Controllers
{
string
?
refreshToken
=
Request
.
Cookies
[
"RefreshToken"
];
if
(
string
.
IsNullOrEmpty
(
refreshToken
))
return
BadRequest
(
"Refresh token is missing."
);
return
Unauthorized
(
"Refresh token is missing."
);
if
(!
_authService
.
ValidateRefreshToken
(
refreshToken
))
return
Unauthorized
(
"Invalid or expired refresh token."
);
...
...
This diff is collapsed.
Click to expand it.
client/src/components/Login/Login.tsx
+
8
−
4
View file @
b4c37340
...
...
@@ -23,16 +23,20 @@ export function Login() {
try
{
const
result
=
await
loginUser
(
formValue
);
giveAuth
();
updateUser
(
result
.
data
);
navigate
(
`/
${
userToDashboard
(
result
.
data
)}
`
);
if
(
result
)
{
giveAuth
();
updateUser
(
result
.
data
);
navigate
(
`/
${
userToDashboard
(
result
.
data
)}
`
);
}
else
{
throw
new
Error
();
}
}
catch
(
error
)
{
const
errorMessage
=
(
error
as
AxiosError
).
response
?.
data
;
if
(
typeof
errorMessage
==
'
string
'
)
{
setError
(
errorMessage
);
}
else
{
setError
(
'
An unexpected error has occurred
'
);
setError
(
'
An unexpected error has occurred
, most likely incorrect credentials
'
);
}
}
};
...
...
This diff is collapsed.
Click to expand it.
client/src/helpers/Api.ts
+
10
−
2
View file @
b4c37340
...
...
@@ -6,11 +6,19 @@ const Api = axios.create({
baseURL
:
'
http://localhost:5267/api/
'
});
const
isAlreadyAuthUrl
=
(
error
:
AxiosError
)
=>
{
const
full
=
error
.
request
.
responseURL
as
string
;
return
full
.
endsWith
(
'
User/authorize
'
);
};
Api
.
interceptors
.
response
.
use
(
(
response
)
=>
response
,
// Normal success logic
(
error
:
AxiosError
)
=>
{
if
(
error
.
request
.
status
===
401
)
{
// If 401 (Unauthorized)
AuthoriseUser
().
then
(()
=>
{
// Re-auth
if
(
error
.
request
.
status
===
401
&&
!
isAlreadyAuthUrl
(
error
))
{
// If 401 (Unauthorized)
AuthoriseUser
().
then
((
response
:
any
)
=>
{
// Re-auth
if
(
!
response
)
// If no response then just return
return
;
return
Api
.
request
(
error
.
config
as
AxiosRequestConfig
);
// Redo the request
});
}
else
{
...
...
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