Skip to content

Commit 2b840de

Browse files
committed
feat(sign-up): updated auth logic
1 parent 580cdbf commit 2b840de

18 files changed

+313
-373
lines changed

src/app/app.routes.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Routes } from '@angular/router';
44

55
import { BookmarksState, ProjectsState } from '@shared/stores';
66

7-
import { authGuard } from './core/guards';
7+
import { authGuard, redirectIfLoggedInGuard } from './core/guards';
88
import { MyProfileResourceFiltersOptionsState } from './features/my-profile/components/filters/store';
99
import { MyProfileResourceFiltersState } from './features/my-profile/components/my-profile-resource-filters/store';
1010
import { MyProfileState } from './features/my-profile/store';
@@ -20,7 +20,9 @@ export const routes: Routes = [
2020
{
2121
path: '',
2222
pathMatch: 'full',
23-
loadComponent: () => import('./features/home/home.component').then((mod) => mod.HomeComponent),
23+
canActivate: [redirectIfLoggedInGuard],
24+
loadComponent: () => import('@osf/features/home/home.component').then((mod) => mod.HomeComponent),
25+
data: { skipBreadcrumbs: true },
2426
},
2527
{
2628
path: 'dashboard',
@@ -29,14 +31,6 @@ export const routes: Routes = [
2931
data: { skipBreadcrumbs: true },
3032
canActivate: [authGuard],
3133
},
32-
{
33-
path: 'home',
34-
loadComponent: () =>
35-
import('@osf/features/home/pages/home-logged-out/home-logged-out.component').then(
36-
(mod) => mod.HomeLoggedOutComponent
37-
),
38-
data: { skipBreadcrumbs: true },
39-
},
4034
{
4135
path: 'confirm/:userId/:token',
4236
loadComponent: () => import('./features/home/home.component').then((mod) => mod.HomeComponent),

src/app/core/components/nav-menu/nav-menu.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { Component, computed, inject, output } from '@angular/core';
1111
import { toSignal } from '@angular/core/rxjs-interop';
1212
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive } from '@angular/router';
1313

14-
import { MODERATION_MENU_ITEM, PROJECT_MENU_ITEMS, REGISTRATION_MENU_ITEMS } from '@core/constants';
15-
import { NavigationService } from '@core/services';
14+
import { MENU_ITEMS, MODERATION_MENU_ITEM, PROJECT_MENU_ITEMS, REGISTRATION_MENU_ITEMS } from '@core/constants';
15+
import { filterMenuItems } from '@osf/core/helpers';
1616
import { ProviderSelectors } from '@osf/core/store/provider';
1717
import { UserSelectors } from '@osf/core/store/user';
1818
import { AuthSelectors } from '@osf/features/auth/store';
@@ -29,7 +29,6 @@ export class NavMenuComponent {
2929

3030
private readonly router = inject(Router);
3131
private readonly route = inject(ActivatedRoute);
32-
private readonly navigationService = inject(NavigationService);
3332

3433
private readonly isAuthenticated = select(AuthSelectors.isAuthenticated);
3534

@@ -61,7 +60,7 @@ export class NavMenuComponent {
6160

6261
protected readonly mainMenuItems = computed(() => {
6362
const isAuthenticated = this.isAuthenticated();
64-
const menuItems = this.navigationService.getFilteredMenuItems(isAuthenticated);
63+
const menuItems = filterMenuItems(MENU_ITEMS, isAuthenticated);
6564

6665
if (this.isRegistryRouteDetails()) {
6766
menuItems.map((menuItem) => {

src/app/core/constants/ngxs-states.constant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { ProviderState } from '@core/store/provider';
22
import { UserState } from '@core/store/user';
3+
import { AuthState } from '@osf/features/auth/store';
34
import { MeetingsState } from '@osf/features/meetings/store';
45
import { ProjectMetadataState } from '@osf/features/project/metadata/store';
56
import { ProjectOverviewState } from '@osf/features/project/overview/store';
67
import { RegistrationsState } from '@osf/features/project/registrations/store';
78
import { AccountSettingsState } from '@osf/features/settings/account-settings/store/account-settings.state';
89
import { DeveloperAppsState } from '@osf/features/settings/developer-apps/store';
910
import { NotificationSubscriptionState } from '@osf/features/settings/notifications/store';
10-
import { AddonsState, InstitutionsState, WikiState } from '@shared/stores';
11+
import { AddonsState, InstitutionsState, WikiState } from '@osf/shared/stores';
1112
import { LicensesState } from '@shared/stores/licenses';
1213
import { MyResourcesState } from '@shared/stores/my-resources';
1314
import { RegionsState } from '@shared/stores/regions';
1415

1516
export const STATES = [
17+
AuthState,
1618
AddonsState,
1719
UserState,
1820
ProviderState,

src/app/core/guards/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { authGuard } from './auth.guard';
2+
export { redirectIfLoggedInGuard } from './redirect-if-logged-in.guard';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inject } from '@angular/core';
2+
import { CanActivateFn, Router } from '@angular/router';
3+
4+
import { AuthService } from '@osf/features/auth/services';
5+
6+
export const redirectIfLoggedInGuard: CanActivateFn = () => {
7+
const authService = inject(AuthService);
8+
const router = inject(Router);
9+
10+
if (authService.isAuthenticated()) {
11+
return router.navigate(['/dashboard']);
12+
}
13+
14+
return true;
15+
};

src/app/core/helpers/nav-menu.helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { MenuItem } from 'primeng/api';
22

33
import { AUTHENTICATED_MENU_ITEMS } from '../constants';
44

5-
export function filterMenuItemsByAuth(items: MenuItem[], isAuthenticated: boolean): MenuItem[] {
5+
export function filterMenuItems(items: MenuItem[], isAuthenticated: boolean): MenuItem[] {
66
return items.map((item) => {
77
const isAuthenticatedItem = AUTHENTICATED_MENU_ITEMS.includes(item.id || '');
88
const shouldShow = isAuthenticated || !isAuthenticatedItem;
99

1010
const updatedItem = { ...item, visible: shouldShow };
1111

1212
if (item.items) {
13-
updatedItem.items = filterMenuItemsByAuth(item.items, isAuthenticated);
13+
updatedItem.items = filterMenuItems(item.items, isAuthenticated);
1414
}
1515

1616
return updatedItem;

src/app/core/interceptors/auth.interceptor.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ export const authInterceptor: HttpInterceptorFn = (
1010
next: HttpHandlerFn
1111
): Observable<HttpEvent<unknown>> => {
1212
const cookieService = inject(CookieService);
13-
// TODO: remove this after the migration to the new auth approach is complete
14-
const authToken = '2rjFZwmdDG4rtKj7hGkEMO6XyHBM2lN7XBbsA1e8OqcFhOWu6Z7fQZiheu9RXtzSeVrgOt';
15-
// UlO9O9GNKgVzJD7pUeY53jiQTKJ4U2znXVWNvh0KZQruoENuILx0IIYf9LoDz7Duq72EIm kyrylo
16-
// 2rjFZwmdDG4rtKj7hGkEMO6XyHBM2lN7XBbsA1e8OqcFhOWu6Z7fQZiheu9RXtzSeVrgOt roman nastyuk
17-
// yZ485nN6MfhqvGrfU4Xk5BEnq0T6LM50nQ6H9VrYaMTaZUQNTuxnIwlp0Wpz879RCsK9GQ NM stage3
18-
const localStorageToken = localStorage.getItem('authToken');
19-
20-
const token = localStorageToken || authToken;
2113

2214
const csrfToken = cookieService.get('api-csrf');
2315

@@ -27,10 +19,6 @@ export const authInterceptor: HttpInterceptorFn = (
2719
'Content-Type': 'application/vnd.api+json',
2820
};
2921

30-
if (token) {
31-
headers['Authorization'] = `Bearer ${token}`;
32-
}
33-
3422
if (csrfToken) {
3523
headers['X-CSRFToken'] = csrfToken;
3624
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import { MenuItem } from 'primeng/api';
2-
31
import { Injectable } from '@angular/core';
42

5-
import { MENU_ITEMS } from '../constants';
6-
import { filterMenuItemsByAuth } from '../helpers';
7-
83
import { environment } from 'src/environments/environment';
94

105
@Injectable({
@@ -15,8 +10,4 @@ export class NavigationService {
1510
const loginUrl = `${environment.casUrl}/login?service=${environment.webUrl}/login`;
1611
window.location.href = loginUrl;
1712
}
18-
19-
getFilteredMenuItems(isAuthenticated: boolean): MenuItem[] {
20-
return filterMenuItemsByAuth(MENU_ITEMS, isAuthenticated);
21-
}
2213
}

src/app/features/home/pages/home-logged-out/data.ts renamed to src/app/features/home/constants/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const slides = [
1+
export const SLIDES = [
22
{
33
img: 'assets/images/carousel1.png',
44
name: 'Patricia Ayala',
@@ -22,7 +22,7 @@ export const slides = [
2222
},
2323
];
2424

25-
export const integrationIcons = [
25+
export const INTEGRATION_ICONS = [
2626
{
2727
title: 'home.loggedOut.integrations.categories.authentication',
2828
first: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './data';

0 commit comments

Comments
 (0)