aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Angular
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Angular')
-rw-r--r--src/DevHive.Angular/src/app/components/feed/feed.component.ts30
-rw-r--r--src/DevHive.Angular/src/app/components/login/login.component.ts2
2 files changed, 17 insertions, 15 deletions
diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
index f583078..0684ddb 100644
--- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts
+++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
@@ -29,6 +29,11 @@ export class FeedComponent implements OnInit {
}
ngOnInit(): void {
+ if (!this._tokenService.getTokenFromSessionStorage()) {
+ this._router.navigate(['/login']);
+ return;
+ }
+
this.posts = [];
this.user = this._userService.getDefaultUser();
@@ -40,19 +45,15 @@ export class FeedComponent implements OnInit {
newPostMessage: new FormControl('')
});
- if (sessionStorage.getItem('UserCred')) {
- this._userService.getUserFromSessionStorageRequest().subscribe(
- (res: object) => {
- Object.assign(this.user, res);
- this.loadFeed();
- },
- (err: HttpErrorResponse) => {
- this.logout();
- }
- );
- } else {
- this._router.navigate(['/login']);
- }
+ this._userService.getUserFromSessionStorageRequest().subscribe(
+ (res: object) => {
+ Object.assign(this.user, res);
+ this.loadFeed();
+ },
+ (err: HttpErrorResponse) => {
+ this.logout();
+ }
+ );
}
private loadFeed(): void {
@@ -62,6 +63,7 @@ export class FeedComponent implements OnInit {
this.finishUserLoading();
},
(err: HttpErrorResponse) => {
+ const test = err.status;
this.finishUserLoading();
}
);
@@ -87,7 +89,7 @@ export class FeedComponent implements OnInit {
createPost(): void {
const postMessage = this.createPostFormGroup.get('newPostMessage')?.value;
- this._postService.createPostFromSessionStorageRequest(postMessage).subscribe(
+ this._postService.createPostWithSessionStorageRequest(postMessage).subscribe(
(result: object) => {
this.goToProfile();
}
diff --git a/src/DevHive.Angular/src/app/components/login/login.component.ts b/src/DevHive.Angular/src/app/components/login/login.component.ts
index 6e285db..c3fb79c 100644
--- a/src/DevHive.Angular/src/app/components/login/login.component.ts
+++ b/src/DevHive.Angular/src/app/components/login/login.component.ts
@@ -35,7 +35,7 @@ export class LoginComponent implements OnInit {
onSubmit(): void {
this._errorBar.hideError();
this._userService.loginUserRequest(this.loginUserFormGroup).subscribe(
- res => {
+ (res: object) => {
this._tokenService.setUserTokenToSessionStorage(res);
this._router.navigate(['/']);
},