wip
This commit is contained in:
parent
6d16458c71
commit
81aa96a77b
6 changed files with 18 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Component, inject } from '@angular/core';
|
import { Component, inject } from '@angular/core';
|
||||||
import { RouterModule, RouterOutlet, RouterLink } from '@angular/router';
|
import { RouterModule, RouterOutlet, RouterLink, RouterLinkActive } from '@angular/router';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { AuthService } from './login/auth.service';
|
import { AuthService } from './login/auth.service';
|
||||||
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
||||||
|
@ -22,6 +22,7 @@ import {
|
||||||
RouterOutlet,
|
RouterOutlet,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
RouterLink,
|
RouterLink,
|
||||||
|
RouterLinkActive,
|
||||||
NgIconComponent,
|
NgIconComponent,
|
||||||
],
|
],
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
import { provideRouter, withDebugTracing } from '@angular/router';
|
||||||
import { environment } from './../environments/environment';
|
import { environment } from './../environments/environment';
|
||||||
import {
|
import {
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
|
@ -43,7 +43,7 @@ export function authIntercept(
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||||
provideRouter(routes),
|
provideRouter(routes, withDebugTracing()),
|
||||||
provideHttpClient(withInterceptors([apiBaseInterceptor, authIntercept])),
|
provideHttpClient(withInterceptors([apiBaseInterceptor, authIntercept])),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,9 +11,9 @@ import { ImportComponent } from './talkgroups/import/import.component';
|
||||||
import { AuthGuard } from './auth.guard';
|
import { AuthGuard } from './auth.guard';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: '', redirectTo: 'login', pathMatch: 'full' },
|
|
||||||
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
|
|
||||||
{ path: 'login', component: LoginComponent },
|
{ path: 'login', component: LoginComponent },
|
||||||
|
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
|
||||||
|
{ path: '**', redirectTo: '' },
|
||||||
{ path: 'talkgroups', component: TalkgroupsComponent },
|
{ path: 'talkgroups', component: TalkgroupsComponent },
|
||||||
{ path: 'talkgroups/import', component: ImportComponent },
|
{ path: 'talkgroups/import', component: ImportComponent },
|
||||||
{ path: 'talkgroups/:sys/:tg', component: TalkgroupRecordComponent },
|
{ path: 'talkgroups/:sys/:tg', component: TalkgroupRecordComponent },
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
import { CanActivateFn } from '@angular/router';
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
|
||||||
export const AuthGuard: CanActivateFn = (route, state) => {
|
export class AuthGuard implements CanActivate {
|
||||||
if (sessionStorage.getItem('jwt') == null) {
|
constructor(private router: Router) { }
|
||||||
|
|
||||||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
|
if (sessionStorage.getItem('jwt') != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -187,7 +187,7 @@ func (a *Auth) routeAuth(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch r.Header.Get("Content-Type") {
|
switch strings.Split(r.Header.Get("Content-Type"), ";")[0] {
|
||||||
case "application/json":
|
case "application/json":
|
||||||
err = json.NewDecoder(r.Body).Decode(&creds)
|
err = json.NewDecoder(r.Body).Decode(&creds)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -62,15 +62,6 @@ func (s *Server) setupRoutes() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) notFoundRedirect(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if strings.HasPrefix(strings.TrimLeft(r.URL.Path, "/"), "api/") {
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Redirect(w, r, "/index.html", http.StatusFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) rateLimit(r chi.Router) {
|
func (s *Server) rateLimit(r chi.Router) {
|
||||||
if s.conf.RateLimit.Verify() {
|
if s.conf.RateLimit.Verify() {
|
||||||
r.Use(rateLimiter(&s.conf.RateLimit))
|
r.Use(rateLimiter(&s.conf.RateLimit))
|
||||||
|
@ -89,7 +80,7 @@ func (s *Server) clientRoute(r chi.Router, clientRoot fs.FS) {
|
||||||
f, err := hfs.Open(pc)
|
f, err := hfs.Open(pc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, &pe) {
|
if errors.As(err, &pe) {
|
||||||
s.notFoundRedirect(w, r)
|
http.ServeFileFS(w, r, clientRoot, "/index.html")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue