Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review 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
tddd96-grupp1
teknikattan-scoring-system
Commits
7459544f
Commit
7459544f
authored
3 years ago
by
Björn Modée
Browse files
Options
Downloads
Patches
Plain Diff
Add comments
parent
619f15b9
No related branches found
No related tags found
No related merge requests found
Pipeline
#46740
passed with warnings
3 years ago
Stage: setup
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/src/utils/checkAuthenticationAdmin.ts
+10
-6
10 additions, 6 deletions
client/src/utils/checkAuthenticationAdmin.ts
client/src/utils/checkAuthenticationCompetition.ts
+10
-5
10 additions, 5 deletions
client/src/utils/checkAuthenticationCompetition.ts
with
20 additions
and
11 deletions
client/src/utils/checkAuthenticationAdmin.ts
+
10
−
6
View file @
7459544f
...
...
@@ -6,32 +6,36 @@ import Types from '../actions/types'
import
{
logoutUser
}
from
'
../actions/user
'
import
store
from
'
../store
'
/** The user is not authorized => logout the user*/
const
UnAuthorized
=
async
()
=>
{
await
logoutUser
()(
store
.
dispatch
)
}
export
const
CheckAuthenticationAdmin
=
async
()
=>
{
const
authToken
=
localStorage
.
token
const
authToken
=
localStorage
.
token
// Retrives from local storage
if
(
authToken
)
{
const
decodedToken
:
any
=
jwtDecode
(
authToken
)
// If the user has an authtoken
const
decodedToken
:
any
=
jwtDecode
(
authToken
)
// Decode it
if
(
decodedToken
.
exp
*
1000
>=
Date
.
now
())
{
// Check expiration data anb if it is still valid
axios
.
defaults
.
headers
.
common
[
'
Authorization
'
]
=
authToken
store
.
dispatch
({
type
:
Types
.
LOADING_USER
})
await
axios
.
get
(
'
/api/users
'
)
.
then
((
res
)
=>
{
store
.
dispatch
({
type
:
Types
.
SET_AUTHENTICATED
})
store
.
dispatch
({
type
:
Types
.
SET_AUTHENTICATED
})
// Make user authenticated
store
.
dispatch
({
type
:
Types
.
SET_USER
,
payload
:
res
.
data
,
})
})
.
catch
((
error
)
=>
{
console
.
log
(
error
)
UnAuthorized
()
// An error has occured
console
.
log
(
error
)
// Log the error
UnAuthorized
()
// The user is not authorized
})
}
else
{
await
UnAuthorized
()
await
UnAuthorized
()
// The user is not authorized
}
}
}
This diff is collapsed.
Click to expand it.
client/src/utils/checkAuthenticationCompetition.ts
+
10
−
5
View file @
7459544f
...
...
@@ -9,19 +9,23 @@ import { getPresentationCompetition, setPresentationCode } from '../actions/pres
import
Types
from
'
../actions/types
'
import
store
from
'
../store
'
/** The user is not authorized => logout the user*/
const
UnAuthorized
=
async
(
role
:
'
Judge
'
|
'
Operator
'
|
'
Team
'
|
'
Audience
'
)
=>
{
await
logoutCompetition
(
role
)(
store
.
dispatch
)
}
export
const
CheckAuthenticationCompetition
=
async
(
role
:
'
Judge
'
|
'
Operator
'
|
'
Team
'
|
'
Audience
'
)
=>
{
const
authToken
=
localStorage
[
`
${
role
}
Token`
]
const
authToken
=
localStorage
[
`
${
role
}
Token`
]
// Retrives from local storage
if
(
authToken
)
{
const
decodedToken
:
any
=
jwtDecode
(
authToken
)
// If the user has an authtoken
const
decodedToken
:
any
=
jwtDecode
(
authToken
)
// Decode it
// Check expiration data anb if it is still valid
if
(
decodedToken
.
exp
*
1000
>=
Date
.
now
())
{
axios
.
defaults
.
headers
.
common
[
'
Authorization
'
]
=
authToken
await
axios
.
get
(
'
/api/auth/test
'
)
.
then
(()
=>
{
// Make user authenticated
store
.
dispatch
({
type
:
Types
.
SET_COMPETITION_LOGIN_DATA
,
payload
:
{
...
...
@@ -34,11 +38,12 @@ export const CheckAuthenticationCompetition = async (role: 'Judge' | 'Operator'
setPresentationCode
(
decodedToken
.
code
)(
store
.
dispatch
)
})
.
catch
((
error
)
=>
{
console
.
log
(
error
)
UnAuthorized
(
role
)
// An error has occured
console
.
log
(
error
)
// Log the error
UnAuthorized
(
role
)
// The user is not authorized
})
}
else
{
await
UnAuthorized
(
role
)
await
UnAuthorized
(
role
)
// The user is not authorized
}
}
}
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