GithubHelp home page GithubHelp logo

classicvalues / ionic-angular-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrewjbateman/ionic-angular-auth

0.0 1.0 0.0 3.78 MB

:clipboard: Ionic Authorization app using jwt tokens. Tutorial code from Simon Grimm of the Ionic Academy

JavaScript 6.25% TypeScript 62.70% HTML 18.03% SCSS 13.02%

ionic-angular-auth's Introduction

โšก Ionic Angular Auth

  • App to prevent access to 'members' route if user not authorized. Authorization is via email & password converted to a JWT token instead of using a backend.
  • Another great tutorial from Simon Grimm of the IonicAcademy' - see ๐Ÿ‘ Inspiration below.
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

๐Ÿ“„ Table of contents

๐Ÿ“š General info

  • Initial screen is a login page with email and password fields.
  • Angular 'canActivate' authguard limits access to the 'members/' route to only authorised (JWT token-bearing) users.
  • Example login details stored in app to test login system and avoid the need for a backend
  • Correct login credentials routes user to 'member' page
  • User credentials stored in Ionic storage so they can be viewed in Dev console/Application/Storage/Ionic Storage/_ionickv
  • Note: the 'register' page does not actually do anything

๐Ÿ“ท Screenshots

screenshot

๐Ÿ“ถ Technologies

๐Ÿ’พ Setup

  • Run npm i to install dependencies
  • To start the server on localhost://8100 type: 'ionic serve'
  • App uses example credentials to test system. There is no connection to an external database etc.
  • To start the server on a mobile using Ionic devapp and connected via wifi, type: 'ionic serve --devapp'
  • The Ionic DevApp was installed on an Android device from the Google Play app store.

๐Ÿ’ป Code Examples from Simon Grimm of the IonicAcademy'

  • canActivate function uses auth service to see if user authorized.
// uses auth.service to check if user has token in storage. Returns true if there is a token
// returns false if user does not have a token and navigates to initial login page.
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {
  return this.auth.user.pipe(
    take(1),
    map(user => {
      console.log('Can activate: ', user);
      if (!user) {
        this.alertCtrl.create({
          header: 'Unauthorized',
          message: 'You are not allowed to access that page.',
          buttons: ['OK']
        }).then(alert => alert.present());

        this.router.navigateByUrl('/');
        return false;
      } else {
        return true;
      }
    })
  );
}

๐Ÿ†’ Features

  • JWT token generated and stored using Ionic Storage - viewable in the Dev console.
  • AuthGuard canActivate only true with this token. Token removed upon logging out.

๐Ÿ“‹ Status & To-do list

  • Status: Working. Tested using ionic server and dummy user credentials to replace 'register' function.
  • To-do: Nothing

๐Ÿ‘ Inspiration

๐Ÿ“ License

  • This project is licensed under the terms of the MIT license.

โœ‰๏ธ Contact

ionic-angular-auth's People

Contributors

andrewjbateman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.