diff --git a/client/admin/src/app/app.component.ts b/client/admin/src/app/app.component.ts index 0ba2ca6..753f207 100644 --- a/client/admin/src/app/app.component.ts +++ b/client/admin/src/app/app.component.ts @@ -1,5 +1,5 @@ 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 { AuthService } from './login/auth.service'; import { NgIconComponent, provideIcons } from '@ng-icons/core'; @@ -22,6 +22,7 @@ import { RouterOutlet, RouterModule, RouterLink, + RouterLinkActive, NgIconComponent, ], templateUrl: './app.component.html', diff --git a/client/admin/src/app/app.config.ts b/client/admin/src/app/app.config.ts index 5c4a112..dd9ab72 100644 --- a/client/admin/src/app/app.config.ts +++ b/client/admin/src/app/app.config.ts @@ -1,5 +1,5 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; -import { provideRouter } from '@angular/router'; +import { provideRouter, withDebugTracing } from '@angular/router'; import { environment } from './../environments/environment'; import { HttpRequest, @@ -43,7 +43,7 @@ export function authIntercept( export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), - provideRouter(routes), + provideRouter(routes, withDebugTracing()), provideHttpClient(withInterceptors([apiBaseInterceptor, authIntercept])), ], }; diff --git a/client/admin/src/app/app.routes.ts b/client/admin/src/app/app.routes.ts index 045f81a..911f00f 100644 --- a/client/admin/src/app/app.routes.ts +++ b/client/admin/src/app/app.routes.ts @@ -11,9 +11,9 @@ import { ImportComponent } from './talkgroups/import/import.component'; import { AuthGuard } from './auth.guard'; export const routes: Routes = [ - { path: '', redirectTo: 'login', pathMatch: 'full' }, - { path: 'home', component: HomeComponent, canActivate: [AuthGuard] }, { path: 'login', component: LoginComponent }, + { path: '', component: HomeComponent, canActivate: [AuthGuard] }, + { path: '**', redirectTo: '' }, { path: 'talkgroups', component: TalkgroupsComponent }, { path: 'talkgroups/import', component: ImportComponent }, { path: 'talkgroups/:sys/:tg', component: TalkgroupRecordComponent }, diff --git a/client/admin/src/app/auth.guard.ts b/client/admin/src/app/auth.guard.ts index f5065e2..d45e6dc 100644 --- a/client/admin/src/app/auth.guard.ts +++ b/client/admin/src/app/auth.guard.ts @@ -1,9 +1,14 @@ -import { CanActivateFn } from '@angular/router'; +import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; -export const AuthGuard: CanActivateFn = (route, state) => { - if (sessionStorage.getItem('jwt') == null) { +export class AuthGuard implements CanActivate { + 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; - } else { - return true; } }; diff --git a/pkg/auth/jwt.go b/pkg/auth/jwt.go index 561716d..bb8501c 100644 --- a/pkg/auth/jwt.go +++ b/pkg/auth/jwt.go @@ -187,7 +187,7 @@ func (a *Auth) routeAuth(w http.ResponseWriter, r *http.Request) { var err error - switch r.Header.Get("Content-Type") { + switch strings.Split(r.Header.Get("Content-Type"), ";")[0] { case "application/json": err = json.NewDecoder(r.Body).Decode(&creds) default: diff --git a/pkg/server/routes.go b/pkg/server/routes.go index 80eaa31..1a014f4 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -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) { if s.conf.RateLimit.Verify() { 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) if err != nil { if errors.As(err, &pe) { - s.notFoundRedirect(w, r) + http.ServeFileFS(w, r, clientRoot, "/index.html") return } } else {