Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Meu-Template-Angular-CSR
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Trần Anh Phú
Meu-Template-Angular-CSR
Commits
a0c87f85
Commit
a0c87f85
authored
Oct 24, 2024
by
vtduong0912
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: store token & role into localStorage
parent
e2113669
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
4 deletions
+8
-4
admin.guard.ts
src/app/+login/data-access/guard/admin.guard.ts
+2
-0
login.model.ts
src/app/+login/data-access/model/login.model.ts
+2
-1
auth.service.ts
src/app/+login/data-access/service/auth.service.ts
+2
-2
login.component.ts
src/app/+login/feature/login.component.ts
+2
-1
No files found.
src/app/+login/data-access/guard/admin.guard.ts
View file @
a0c87f85
...
...
@@ -8,5 +8,7 @@ export class AdminGuard implements CanActivate {
constructor
()
{}
canActivate
():
boolean
{
return
true
;
// return false if user role is not admin
// return false;
}
}
src/app/+login/data-access/model/login.model.ts
View file @
a0c87f85
...
...
@@ -3,7 +3,8 @@ export namespace Login {
user
:
{
username
:
string
,
role
:
string
,
}
},
accessToken
:
string
,
};
export
type
Request
=
{
...
...
src/app/+login/data-access/service/auth.service.ts
View file @
a0c87f85
...
...
@@ -9,8 +9,8 @@ import { Observable, map } from "rxjs";
})
export
class
AuthService
{
constructor
(
private
_http
:
HttpClient
)
{
}
private
_http
:
HttpClient
,
)
{}
loginPost
(
request
:
Login
.
Request
)
{
return
this
.
_http
...
...
src/app/+login/feature/login.component.ts
View file @
a0c87f85
...
...
@@ -70,7 +70,8 @@ export class LoginComponent implements OnInit {
}
onSuccess
(
response
:
ResponseResult
<
Login
.
Response
>
)
{
console
.
log
(
response
);
localStorage
.
setItem
(
"token"
,
JSON
.
stringify
(
response
.
responseData
?.
accessToken
)
??
""
);
localStorage
.
setItem
(
"role"
,
JSON
.
stringify
(
response
.
responseData
?.
user
.
role
)
??
""
);
this
.
_router
.
navigate
([
'/home'
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment