All Projects → aaronksaunders → ionic4-sidemenu-auth

aaronksaunders / ionic4-sidemenu-auth

Licence: other
Building a Basic Ionic 4 Login Flow with Angular Router & Side Menu UI

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ionic4-sidemenu-auth

Tutorials
Start solving PDEs in Julia with Gridap.jl
Stars: ✭ 79 (+132.35%)
Mutual labels:  tutorials
tutorials
Collection of tutorials for various libraries and technologies
Stars: ✭ 98 (+188.24%)
Mutual labels:  tutorials
PlutoStaticHTML.jl
Convert Pluto notebooks to HTML in automated workflows
Stars: ✭ 69 (+102.94%)
Mutual labels:  tutorials
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (+8.82%)
Mutual labels:  javascript-library
ts-init
Minimalist TypeScript package initializer - like `npm init`, but for TS.
Stars: ✭ 27 (-20.59%)
Mutual labels:  javascript-library
picoCSS
picoCSS - really small JavaScript Framework
Stars: ✭ 62 (+82.35%)
Mutual labels:  javascript-library
Kursor
Cursor style with javascript and css
Stars: ✭ 140 (+311.76%)
Mutual labels:  javascript-library
amirajs
Amirajs is Lightweight (~0.4kb compressed) JS Library for DOM Manipulation
Stars: ✭ 12 (-64.71%)
Mutual labels:  javascript-library
YouTube tutorial
I store all the code I used in my YouTube tutorial here. Feel free to download and play around them😉
Stars: ✭ 56 (+64.71%)
Mutual labels:  tutorials
tung
A javascript library for rendering html
Stars: ✭ 29 (-14.71%)
Mutual labels:  javascript-library
ctxmenu
Tiny and customizable context menu generator
Stars: ✭ 20 (-41.18%)
Mutual labels:  javascript-library
Mei.js
a minimal, simple and helpful library for you
Stars: ✭ 15 (-55.88%)
Mutual labels:  javascript-library
DevHelpBox
we are creating this community so that other developers can get benefits of it.
Stars: ✭ 35 (+2.94%)
Mutual labels:  javascript-library
animeflv
Animeflv is a custom API that has the entire catalog of the animeflv.net website. You can enjoy all the content with subtitles in Spanish and the latest in the world of anime for free.
Stars: ✭ 37 (+8.82%)
Mutual labels:  javascript-library
ogl to vlk
Vulkan Tutorials For OpenGL Developers
Stars: ✭ 16 (-52.94%)
Mutual labels:  tutorials
travis-ci-tutorial-java
Just to learn how to use travis-ci in a java project!
Stars: ✭ 38 (+11.76%)
Mutual labels:  tutorials
react-native-curated
💁‍♂️ Hand picked collection of packages, tutorials and more for React Native.
Stars: ✭ 43 (+26.47%)
Mutual labels:  tutorials
docs
Documentation site for LFE
Stars: ✭ 23 (-32.35%)
Mutual labels:  tutorials
piggy-bank
Nodejs with Ethereum smart contract tutorial app
Stars: ✭ 19 (-44.12%)
Mutual labels:  tutorials
app-starter
Angular mono-repo (Ionic/Capacitor/StencilJS/Web Component) app starter for supporting cross platform apps.
Stars: ✭ 75 (+120.59%)
Mutual labels:  ionic4

ionic4-sidemenu-auth

Building a Basic Ionic 4 Login Flow with Angular Router & Side Menu UI ( now with Tabs !! )

Updated to latest Ionic Versions

Ionic:

   Ionic CLI                     : 5.4.13 (/Users/aaronksaunders/.nvm/versions/node/v10.15.1/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.11.7
   @angular-devkit/build-angular : 0.803.21
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.1.1

Utility:

   cordova-res                          : not installed
   native-run (update available: 0.3.0) : 0.2.9

System:

   NodeJS : v10.15.1 (/Users/aaronksaunders/.nvm/versions/node/v10.15.1/bin/node)
   npm    : 6.11.2
   OS     : macOS Catalina
  • Code recently updated to latest version of Ionic "@ionic/angular": "^4.3.0",
  • Made it a bit more complex with
    • Authentication
    • Side Menu
    • Tabs
    • Tab Detail Page
  • based on great work done here - https://devdactic.com/ionic-4-login-angular/

How It Works

We put an AuthGuard on the module that provides access to all of the member related pages and functionality. The login page has no gaurd so it can be freely accessed. See more information on Route Guards in the angular.io documentation

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { 
    path: 'members', 
    canActivate: [AuthGuardService],
    loadChildren: './members/member-routing.module#MemberRoutingModule'
  },
  { path: 'login', loadChildren: './public/login/login.module#LoginPageModule' }
];

The member routing module is where we control access to the private content. An import note from the documentation is what supports this approach.

The Routing Module is a design choice whose value is most obvious when the configuration is complex and includes specialized guard and resolver services. It can seem like overkill when the actual configuration is dead simple. See more information on Routing Modules in the Angular.io Documentation

We created the authentication.service to track in the user is logged in or out and to manage the two different states.

// file: authentication.service.ts
export class AuthenticationService {
  isLoggedIn = false;

  constructor() {}

  setLoggedIn(_value) {
    this.isLoggedIn = _value;
  }
  isAuthenticated(): boolean {
    return this.isLoggedIn;
  }
}

This service is injected into the AuthGuard to help control access to a specific route.

  // file: authGuard.service.ts
  canActivate(): boolean {
    let value = this.auth.isAuthenticated() // <= from auth service
    if (!value) {
      this.router.navigateByUrl("/login")
    }
    return value
  }
}

and it is also used in the user interface, app.component.html to control the visibility of the side-menu. Meaning if you are not authenticated than the side menu isnt going to be showing.

<!-- file: app.component.html -->
<ion-app>
  <ion-split-pane>
    <ion-menu *ngIf="auth.isAuthenticated() === true"> // CHECK TO SEE IF THIS SHOULD BE DISPLAYE
      <ion-header>
        <ion-toolbar>
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content>
      // MENU CONTENT
      </ion-content>
    </ion-menu>
    <ion-router-outlet main></ion-router-outlet>
  </ion-split-pane>
</ion-app>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].