mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
[PM-4348] Migrate AuthGuards to functions (#9595)
* Migrate auth guards * Fix remaining auth guard migration * Fix unauth guard usage * Add unit tests for auth guard and unauth guard * Remove unused angular DI code * Move auth related logic out fo sm guard * Add tests * Add more tests for unauth guard * Fix incorrect merge
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export { UnauthGuardService } from "./unauth-guard.service";
|
||||
@@ -1,5 +0,0 @@
|
||||
import { UnauthGuard as BaseUnauthGuardService } from "@bitwarden/angular/auth/guards";
|
||||
|
||||
export class UnauthGuardService extends BaseUnauthGuardService {
|
||||
protected homepage = "tabs/current";
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { Injectable, NgModule } from "@angular/core";
|
||||
import { ActivatedRouteSnapshot, RouteReuseStrategy, RouterModule, Routes } from "@angular/router";
|
||||
|
||||
import {
|
||||
AuthGuard,
|
||||
authGuard,
|
||||
lockGuard,
|
||||
redirectGuard,
|
||||
tdeDecryptionRequiredGuard,
|
||||
@@ -191,7 +191,7 @@ const routes: Routes = [
|
||||
{
|
||||
path: "remove-password",
|
||||
component: RemovePasswordComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "remove-password" },
|
||||
},
|
||||
{
|
||||
@@ -215,162 +215,162 @@ const routes: Routes = [
|
||||
{
|
||||
path: "ciphers",
|
||||
component: VaultItemsComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "ciphers" },
|
||||
},
|
||||
...extensionRefreshSwap(ViewComponent, ViewV2Component, {
|
||||
path: "view-cipher",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "view-cipher" },
|
||||
}),
|
||||
{
|
||||
path: "cipher-password-history",
|
||||
component: PasswordHistoryComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "cipher-password-history" },
|
||||
},
|
||||
...extensionRefreshSwap(AddEditComponent, AddEditV2Component, {
|
||||
path: "add-cipher",
|
||||
canActivate: [AuthGuard, debounceNavigationGuard()],
|
||||
canActivate: [authGuard, debounceNavigationGuard()],
|
||||
data: { state: "add-cipher" },
|
||||
runGuardsAndResolvers: "always",
|
||||
}),
|
||||
...extensionRefreshSwap(AddEditComponent, AddEditV2Component, {
|
||||
path: "edit-cipher",
|
||||
canActivate: [AuthGuard, debounceNavigationGuard()],
|
||||
canActivate: [authGuard, debounceNavigationGuard()],
|
||||
data: { state: "edit-cipher" },
|
||||
runGuardsAndResolvers: "always",
|
||||
}),
|
||||
{
|
||||
path: "share-cipher",
|
||||
component: ShareComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "share-cipher" },
|
||||
},
|
||||
{
|
||||
path: "collections",
|
||||
component: CollectionsComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "collections" },
|
||||
},
|
||||
...extensionRefreshSwap(AttachmentsComponent, AttachmentsV2Component, {
|
||||
path: "attachments",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "attachments" },
|
||||
}),
|
||||
{
|
||||
path: "generator",
|
||||
component: GeneratorComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "generator" },
|
||||
},
|
||||
{
|
||||
path: "generator-history",
|
||||
component: PasswordGeneratorHistoryComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "generator-history" },
|
||||
},
|
||||
...extensionRefreshSwap(ImportBrowserComponent, ImportBrowserV2Component, {
|
||||
path: "import",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "import" },
|
||||
}),
|
||||
...extensionRefreshSwap(ExportBrowserComponent, ExportBrowserV2Component, {
|
||||
path: "export",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "export" },
|
||||
}),
|
||||
...extensionRefreshSwap(AutofillV1Component, AutofillComponent, {
|
||||
path: "autofill",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "autofill" },
|
||||
}),
|
||||
{
|
||||
path: "account-security",
|
||||
component: AccountSecurityComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "account-security" },
|
||||
},
|
||||
...extensionRefreshSwap(NotificationsSettingsV1Component, NotificationsSettingsComponent, {
|
||||
path: "notifications",
|
||||
component: NotificationsSettingsV1Component,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "notifications" },
|
||||
}),
|
||||
...extensionRefreshSwap(VaultSettingsComponent, VaultSettingsV2Component, {
|
||||
path: "vault-settings",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "vault-settings" },
|
||||
}),
|
||||
{
|
||||
path: "folders",
|
||||
component: FoldersComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "folders" },
|
||||
},
|
||||
{
|
||||
path: "add-folder",
|
||||
component: FolderAddEditComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "add-folder" },
|
||||
},
|
||||
{
|
||||
path: "edit-folder",
|
||||
component: FolderAddEditComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "edit-folder" },
|
||||
},
|
||||
{
|
||||
path: "sync",
|
||||
component: SyncComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "sync" },
|
||||
},
|
||||
...extensionRefreshSwap(ExcludedDomainsV1Component, ExcludedDomainsComponent, {
|
||||
path: "excluded-domains",
|
||||
component: ExcludedDomainsV1Component,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "excluded-domains" },
|
||||
}),
|
||||
{
|
||||
path: "premium",
|
||||
component: PremiumComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "premium" },
|
||||
},
|
||||
{
|
||||
path: "appearance",
|
||||
component: AppearanceComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "appearance" },
|
||||
},
|
||||
...extensionRefreshSwap(AddEditComponent, AddEditV2Component, {
|
||||
path: "clone-cipher",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "clone-cipher" },
|
||||
}),
|
||||
{
|
||||
path: "send-type",
|
||||
component: SendTypeComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "send-type" },
|
||||
},
|
||||
{
|
||||
path: "add-send",
|
||||
component: SendAddEditComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "add-send" },
|
||||
},
|
||||
{
|
||||
path: "edit-send",
|
||||
component: SendAddEditComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "edit-send" },
|
||||
},
|
||||
{
|
||||
path: "update-temp-password",
|
||||
component: UpdateTempPasswordComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "update-temp-password" },
|
||||
},
|
||||
{
|
||||
@@ -429,12 +429,12 @@ const routes: Routes = [
|
||||
},
|
||||
...extensionRefreshSwap(AboutPageComponent, AboutPageV2Component, {
|
||||
path: "about",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "about" },
|
||||
}),
|
||||
...extensionRefreshSwap(MoreFromBitwardenPageComponent, MoreFromBitwardenPageV2Component, {
|
||||
path: "more-from-bitwarden",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "moreFromBitwarden" },
|
||||
}),
|
||||
...extensionRefreshSwap(TabsComponent, TabsV2Component, {
|
||||
@@ -449,30 +449,30 @@ const routes: Routes = [
|
||||
{
|
||||
path: "current",
|
||||
component: CurrentTabComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
canMatch: [extensionRefreshRedirect("/tabs/vault")],
|
||||
data: { state: "tabs_current" },
|
||||
runGuardsAndResolvers: "always",
|
||||
},
|
||||
...extensionRefreshSwap(VaultFilterComponent, VaultV2Component, {
|
||||
path: "vault",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "tabs_vault" },
|
||||
}),
|
||||
{
|
||||
path: "generator",
|
||||
component: GeneratorComponent,
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "tabs_generator" },
|
||||
},
|
||||
...extensionRefreshSwap(SettingsComponent, SettingsV2Component, {
|
||||
path: "settings",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "tabs_settings" },
|
||||
}),
|
||||
...extensionRefreshSwap(SendGroupingsComponent, SendV2Component, {
|
||||
path: "send",
|
||||
canActivate: [AuthGuard],
|
||||
canActivate: [authGuard],
|
||||
data: { state: "tabs_send" },
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { APP_INITIALIZER, NgModule, NgZone } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
import { Subject, merge, of } from "rxjs";
|
||||
|
||||
import { UnauthGuard as BaseUnauthGuardService } from "@bitwarden/angular/auth/guards";
|
||||
import { AngularThemingService } from "@bitwarden/angular/platform/services/theming/angular-theming.service";
|
||||
import { SafeProvider, safeProvider } from "@bitwarden/angular/platform/utils/safe-provider";
|
||||
import {
|
||||
@@ -84,7 +82,6 @@ import { TotpService } from "@bitwarden/common/vault/services/totp.service";
|
||||
import { DialogService, ToastService } from "@bitwarden/components";
|
||||
import { PasswordRepromptService } from "@bitwarden/vault";
|
||||
|
||||
import { UnauthGuardService } from "../../auth/popup/services";
|
||||
import { AutofillService as AutofillServiceAbstraction } from "../../autofill/services/abstractions/autofill.service";
|
||||
import AutofillService from "../../autofill/services/autofill.service";
|
||||
import MainBackground from "../../background/main.background";
|
||||
@@ -163,11 +160,6 @@ const safeProviders: SafeProvider[] = [
|
||||
deps: [InitService],
|
||||
multi: true,
|
||||
}),
|
||||
safeProvider({
|
||||
provide: BaseUnauthGuardService,
|
||||
useClass: UnauthGuardService,
|
||||
deps: [AuthService, Router],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: CryptoFunctionService,
|
||||
useFactory: () => new WebCryptoFunctionService(window),
|
||||
|
||||
Reference in New Issue
Block a user