Skip to content

Commit

Permalink
Fixed/Added new features, removed the debugging in console
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokeylooted committed Feb 20, 2023
1 parent ac94eb1 commit 1a6a634
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 105 deletions.
207 changes: 118 additions & 89 deletions Nexus/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Nexus/src/Components/side-bar/side-bar.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: start;
justify-content: flex-start;
width: 100%;
transition: 0.3s all ease-in;
border: 1px solid #F2F4F7;
Expand All @@ -46,7 +46,7 @@
.side_bar .menu_bar .nav-link {
width: 100%;
display: flex;
justify-content: start;
justify-content: flex-start;
align-items: center;
font-style: normal;
font-weight: 400;
Expand Down
5 changes: 2 additions & 3 deletions Nexus/src/Components/side-bar/side-bar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: start;
justify-content: flex-start;
width: 100%;
transition: 0.3s all ease-in;
border: 1px solid #F2F4F7;
box-shadow: 0px 4px 6px -2px rgba(16, 24, 40, 0.03);
border-radius: 25px;
font-family: 'Inter', sans-serif;
&:hover{
background: #FFE8E3;
Expand All @@ -52,7 +51,7 @@
.nav-link{
width: 100%;
display: flex;
justify-content: start;
justify-content: flex-start;
align-items: center;
font-style: normal;
font-weight: 400;
Expand Down
11 changes: 9 additions & 2 deletions Nexus/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ import { LoginComponent } from './login/login.component';
import { MainComponent } from './main/main.component';

const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'dashboard', component: MainComponent, canActivate: [AuthGuard] } as any,
{
path: 'dashboard',
component: MainComponent,
canActivate: [AuthGuard]
},
{
path: '',
component: LoginComponent,
}
];

@NgModule({
Expand Down
5 changes: 3 additions & 2 deletions Nexus/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
Expand Down Expand Up @@ -34,7 +34,8 @@ import { MainComponent } from './main/main.component';
AppRoutingModule,
FormsModule,
HttpClientModule,
CarouselModule
CarouselModule,
BrowserAnimationsModule
],
providers: [{ provide: 'API_URL', useValue: environment.apiUrl }],
bootstrap: [AppComponent]
Expand Down
27 changes: 26 additions & 1 deletion Nexus/src/app/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ export class AuthService {

public logout(): void {
localStorage.removeItem('token');
this.router.navigate(['/']);
this.router.navigate(['/']);
}
public checkToken(): void {
const storedToken = localStorage.getItem('token');

if (!storedToken) {
this.logout();
return;
}

const decodedStoredToken: any = jwt_decode(storedToken);
const currentTime = Date.now() / 1000;
if (decodedStoredToken.exp < currentTime) {
this.logout();
return;
}

const timer = setInterval(() => {
const currentToken = localStorage.getItem('token');
if (!currentToken || currentToken !== storedToken) {
this.logout();
clearInterval(timer);
}
}, 1000);
}
}


13 changes: 9 additions & 4 deletions Nexus/src/app/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { AuthService } from '../auth.service';

@Injectable({
Expand All @@ -11,12 +11,17 @@ export class AuthGuard implements CanActivate {
private router: Router
) {}

canActivate(): boolean {
console.log('AuthGuard: canActivate called');
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (this.authService.isLoggedIn()) {
if (state.url === '/') {
// Redirect to dashboard if user is already logged in and trying to access login page
this.router.navigate(['/dashboard']);
return false;
}
// Allow access to requested page if user is already logged in
return true;
} else {
localStorage.removeItem('token'); // clear invalid token from local storage
// Redirect to login page if user is not logged in
this.router.navigate(['/']);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Nexus/src/app/login/login.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ label {
.form-group label {
font-size: 12px;
margin-bottom: 6px;
align-self: flex-start;
align-self: flex-flex-start;
}

.form-group.password a.forgot-password {
Expand All @@ -216,7 +216,7 @@ label {
letter-spacing: 0.1px;
text-align: right;
margin-bottom: 6px;
align-self: flex-start;
align-self: flex-flex-start;
text-decoration: none;
}

Expand Down

0 comments on commit 1a6a634

Please sign in to comment.