diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index cca6bc30..73c58b15 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,9 +1,11 @@ import { NgModule } from '@angular/core'; import { ExtraOptions, RouterModule, Routes } from '@angular/router'; +import { AuthGuard } from './service/auth-guard.service'; export const routes: Routes = [ { path: 'pages', + canActivate: [AuthGuard], loadChildren: () => import('./pages/pages.module') .then(m => m.PagesModule), }, @@ -11,7 +13,6 @@ export const routes: Routes = [ path: 'auth', loadChildren: () => import('./auth/auth.module').then(m => m.NgxAuthModule) }, - { path: '', redirectTo: 'auth', pathMatch: 'full' }, { path: '**', redirectTo: 'pages' }, ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0710cf73..1ce3a588 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,8 +1,3 @@ -/** - * @license - * Copyright Akveo. All Rights Reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - */ import { HttpClientModule } from '@angular/common/http'; import { NgModule } from '@angular/core'; import { AngularFireModule } from '@angular/fire/compat'; @@ -22,6 +17,9 @@ import { CoreModule } from './@core/core.module'; import { ThemeModule } from './@theme/theme.module'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; +import { AngularFireAuthModule } from '@angular/fire/compat/auth'; + +import { AuthGuard } from './service/auth-guard.service'; @NgModule({ declarations: [AppComponent], @@ -31,6 +29,7 @@ import { AppComponent } from './app.component'; HttpClientModule, AppRoutingModule, AngularFireModule.initializeApp(environment.firebase), + AngularFireAuthModule, NbSidebarModule.forRoot(), NbMenuModule.forRoot(), NbDatepickerModule.forRoot(), @@ -43,6 +42,9 @@ import { AppComponent } from './app.component'; CoreModule.forRoot(), ThemeModule.forRoot(), ], + providers: [ + AuthGuard + ], bootstrap: [AppComponent], }) export class AppModule { diff --git a/src/app/auth/auth-firebase.config.ts b/src/app/auth/auth-firebase.config.ts new file mode 100644 index 00000000..53aa078b --- /dev/null +++ b/src/app/auth/auth-firebase.config.ts @@ -0,0 +1,72 @@ +import { NbAuthStrategyOptions, NbAuthJWTToken, NbPasswordStrategyModule, NbPasswordStrategyMessage } from "@nebular/auth"; + +export class NbFirebasePasswordStrategyOptions extends NbAuthStrategyOptions { + name: string = 'email'; + token = { + class: NbAuthJWTToken, + }; + register?: boolean | NbPasswordStrategyModule = { + redirect: { + success: '/auth/login', + failure: null, + }, + defaultErrors: ['Something went wrong, please try again.'], + defaultMessages: ['You have been successfully registered.'], + }; + login?: boolean | NbPasswordStrategyModule = { + redirect: { + success: '/dashboard', + failure: null, + }, + defaultErrors: ['Login/Email combination is not correct, please try again.'], + defaultMessages: ['You have been successfully logged in.'], + }; + logout?: boolean | NbPasswordStrategyModule = { + redirect: { + success: '/', + failure: null, + }, + defaultErrors: ['Something went wrong, please try again.'], + defaultMessages: ['You have been successfully logged out.'], + }; + refreshToken?: boolean | NbPasswordStrategyModule = { + redirect: { + success: null, + failure: null, + }, + defaultErrors: ['Something went wrong, please try again.'], + defaultMessages: ['Your token has been successfully refreshed.'], + }; + // requestPassword?: boolean | NbPasswordStrategyModule = { + // redirect: { + // success: '/', + // failure: null, + // }, + // defaultErrors: ['Something went wrong, please try again.'], + // defaultMessages: ['Reset password instructions have been sent to your email.'], + // }; + // resetPassword?: boolean | NbPasswordStrategyModule = { + // redirect: { + // success: '/', + // failure: null, + // }, + // defaultErrors: ['Something went wrong, please try again.'], + // defaultMessages: ['Your password has been successfully changed.'], + // }; + // errors?: NbPasswordStrategyMessage = { + // key: 'message', + // getter: (module: string, res, options: NbFirebasePasswordStrategyOptions) => getDeepFromObject( + // res, + // options.errors.key, + // options[module].defaultErrors, + // ), + // }; + // messages?: NbPasswordStrategyMessage = { + // key: 'messages', + // getter: (module: string, res, options: NbFirebasePasswordStrategyOptions) => getDeepFromObject( + // res.body, + // options.messages.key, + // options[module].defaultMessages, + // ), + // }; + } \ No newline at end of file diff --git a/src/app/auth/auth.module.ts b/src/app/auth/auth.module.ts index c0f9ef19..4a542756 100644 --- a/src/app/auth/auth.module.ts +++ b/src/app/auth/auth.module.ts @@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { NgxAuthRoutingModule } from './auth-routing.module'; -import { NbAuthModule } from '@nebular/auth'; +import { NbAuthModule, NbPasswordAuthStrategy } from '@nebular/auth'; import { NbAlertModule, NbButtonModule, @@ -13,6 +13,7 @@ import { } from '@nebular/theme'; import { NgxLoginComponent } from './login/login.component'; import { NgxRegisterComponent } from './register/register.component'; +import { NbFirebasePasswordStrategyOptions } from './auth-firebase.config'; @NgModule({ @@ -26,7 +27,29 @@ import { NgxRegisterComponent } from './register/register.component'; NbCheckboxModule, NgxAuthRoutingModule, - NbAuthModule, + NbAuthModule.forRoot({ + strategies: [ + NbPasswordAuthStrategy.setup({ + name: 'email', + + login: { + redirect: { + success: '/dashboard', + failure: null, // stay on the same page + }, + }, + + register: { + redirect: { + success: '/auth/login', + failure: null, // stay on the same page + }, + }, + ...new NbFirebasePasswordStrategyOptions() + }), + ], + forms: {}, + }), ], declarations: [ // ... here goes our new components diff --git a/src/app/auth/login/login.component.html b/src/app/auth/login/login.component.html index 1889aeec..741f26dc 100644 --- a/src/app/auth/login/login.component.html +++ b/src/app/auth/login/login.component.html @@ -1,7 +1,7 @@
Welcome to RESUME TAILOR!!!
- + --> -