72 lines
3.1 KiB
TypeScript
72 lines
3.1 KiB
TypeScript
import { HttpInterceptorFn, provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
import { bootstrapApplication } from '@angular/platform-browser';
|
|
import { provideRouter, Routes } from '@angular/router';
|
|
import { AppComponent } from './app/app.component';
|
|
import { AccountPasswordComponent } from './app/pages/account-password.component';
|
|
import { AccountOverviewComponent } from './app/pages/account-overview.component';
|
|
import { AccountEditComponent } from './app/pages/account-edit.component';
|
|
import { AccountEmailComponent } from './app/pages/account-email.component';
|
|
import { AdminAuditComponent } from './app/pages/admin-audit.component';
|
|
import { AdminGroupsComponent } from './app/pages/admin-groups.component';
|
|
import { AdminOidcClientsComponent } from './app/pages/admin-oidc-clients.component';
|
|
import { AdminRegistrationsComponent } from './app/pages/admin-registrations.component';
|
|
import { AdminUsersComponent } from './app/pages/admin-users.component';
|
|
import { ForgotPasswordComponent } from './app/pages/forgot-password.component';
|
|
import { LoginComponent } from './app/pages/login.component';
|
|
import { RegisterComponent } from './app/pages/register.component';
|
|
import { ResetPasswordComponent } from './app/pages/reset-password.component';
|
|
import { VerifyEmailComponent } from './app/pages/verify-email.component';
|
|
import { API_BASE_URL } from './app/shared/api-base-url';
|
|
import { AuthService } from './app/shared/auth.service';
|
|
|
|
declare global {
|
|
interface Window {
|
|
__LDAP_PORTAL_CONFIG__?: {
|
|
apiBaseUrl?: string;
|
|
};
|
|
}
|
|
}
|
|
|
|
const authInterceptor: HttpInterceptorFn = (request, next) => {
|
|
const token = localStorage.getItem('accessToken');
|
|
if (!token) {
|
|
return next(request);
|
|
}
|
|
|
|
return next(
|
|
request.clone({
|
|
setHeaders: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}),
|
|
);
|
|
};
|
|
|
|
const routes: Routes = [
|
|
{ path: '', redirectTo: 'login', pathMatch: 'full' },
|
|
{ path: 'login', component: LoginComponent },
|
|
{ path: 'register', component: RegisterComponent },
|
|
{ path: 'verify-email', component: VerifyEmailComponent },
|
|
{ path: 'forgot-password', component: ForgotPasswordComponent },
|
|
{ path: 'reset-password', component: ResetPasswordComponent },
|
|
{ path: 'account', component: AccountOverviewComponent },
|
|
{ path: 'account/edit', component: AccountEditComponent },
|
|
{ path: 'account/email', component: AccountEmailComponent },
|
|
{ path: 'account/password', component: AccountPasswordComponent },
|
|
{ path: 'admin/oidc-clients', component: AdminOidcClientsComponent },
|
|
{ path: 'admin/registrations', component: AdminRegistrationsComponent },
|
|
{ path: 'admin/users', component: AdminUsersComponent },
|
|
{ path: 'admin/groups', component: AdminGroupsComponent },
|
|
{ path: 'admin/audit', component: AdminAuditComponent },
|
|
{ path: '**', redirectTo: 'login' },
|
|
];
|
|
|
|
bootstrapApplication(AppComponent, {
|
|
providers: [
|
|
provideRouter(routes),
|
|
provideHttpClient(withInterceptors([authInterceptor])),
|
|
AuthService,
|
|
{ provide: API_BASE_URL, useValue: window.__LDAP_PORTAL_CONFIG__?.apiBaseUrl ?? '/api' },
|
|
],
|
|
}).catch((error) => console.error(error));
|