DEV Community

Cover image for Angular Authentication: Best Practices šŸ†
Nikos Anifantis
Nikos Anifantis

Posted on

Angular Authentication: Best Practices šŸ†

An Angular application that demonstrates best practices for user authentication flow.

By @nikosanif

GitHub logo nikosanif / angular-authentication

An Angular application that demonstrates best practices for user authentication.

Angular Authentication

An Angular application that demonstrates best practices for user authentication flow.

By @nikosanif

Open in Visual Studio Code license code style: prettier Twitter Follow

Table of Contents

Live Demo

Live application: angular-authentication.netlify.app

Angular Authentication Demo

Getting Started

Prerequisites

Setup & Usage

  • Clone this repository: git clone git@github.com:nikosanif/angular-authentication.git
  • cd angular-authentication
  • Install dependencies: npm install
  • Serve the Angular app: npm start
  • Open your browser at: http://localhost:4200

Useful Commands

  • npm start - starts a dev server of Angular app
  • npm run build - builds full prod build
  • npm run lint - linting source code of this project
  • npm run format:check - runs prettier to check for formatting errors
  • npm run format:write - runs prettier to format whole code base
  • npm run release - runs standard-version to create new release

Features

Authentication Flows

Angular Authentication Demo Angular Authentication Demo

Other Features

  • Lazy loading of Angular modules
  • API requests with @ngrx/effects
  • Responsive design
  • In-memory Web API

Tech Stack

  • ā€¦

Live Demo

Live application: angular-authentication.netlify.app

Angular Authentication Demo

Getting Started

Prerequisites

Setup & Usage

  • Clone this repository: git clone git@github.com:nikosanif/angular-authentication.git
  • cd angular-authentication
  • Install dependencies: npm install
  • Serve the Angular app: npm start
  • Open your browser at: http://localhost:4200

Useful Commands

  • npm start - starts a dev server of Angular app
  • npm run build - builds full prod build
  • npm run lint - linting source code of this project
  • npm run format:check - runs prettier to check for formatting errors
  • npm run format:write - runs prettier to format whole code base
  • npm run release - runs standard-version to create new release

Features

Authentication Flows

Angular Authentication Demo
Angular Authentication Demo

Other Features

  • Lazy loading of Angular modules
  • API requests with @ngrx/effects
  • Responsive design
  • In-memory Web API

Tech Stack

High-level Design

Below is the high-level structure of the application.

./src
ā”œā”€ā”€ app
ā”‚   ā”œā”€ā”€ app # root app component
ā”‚   ā”‚   ā”œā”€ā”€ app.component.html
ā”‚   ā”‚   ā”œā”€ā”€ app.component.scss
ā”‚   ā”‚   ā””ā”€ā”€ app.component.ts
ā”‚   ā”‚
ā”‚   ā”œā”€ā”€ app-routing.module.ts
ā”‚   ā”œā”€ā”€ app.module.ts
ā”‚   ā”‚
ā”‚   ā”œā”€ā”€ auth # includes authentication logic
ā”‚   ā”‚   ā”œā”€ā”€ auth.module.ts
ā”‚   ā”‚   ā”œā”€ā”€ auth.service.ts
ā”‚   ā”‚   ā”œā”€ā”€ guards
ā”‚   ā”‚   ā”œā”€ā”€ interceptors
ā”‚   ā”‚   ā”œā”€ā”€ login
ā”‚   ā”‚   ā””ā”€ā”€ store
ā”‚   ā”‚
ā”‚   ā”œā”€ā”€ core # includes core utilities
ā”‚   ā”‚   ā”œā”€ā”€ core.module.ts
ā”‚   ā”‚   ā”œā”€ā”€ fake-api
ā”‚   ā”‚   ā””ā”€ā”€ services
ā”‚   ā”‚
ā”‚   ā”œā”€ā”€ features # all features of application
ā”‚   ā”‚   ā”œā”€ā”€ about
ā”‚   ā”‚   ā”œā”€ā”€ home
ā”‚   ā”‚   ā””ā”€ā”€ secured-feat
ā”‚   ā”‚
ā”‚   ā””ā”€ā”€ shared # shared UI modules and utilities
ā”‚       ā”œā”€ā”€ ui
ā”‚       ā””ā”€ā”€ util
ā”‚
ā”œā”€ā”€ assets
ā”‚   ā”œā”€ā”€ ...
ā”‚
ā”œā”€ā”€ environments
ā”‚   ā”œā”€ā”€ environment.prod.ts
ā”‚   ā””ā”€ā”€ environment.ts
ā”‚
ā”œā”€ā”€ ...
ā”‚
ā””ā”€ā”€ theme # global theme styles
    ā”œā”€ā”€ _components.scss
    ā”œā”€ā”€ _typography.scss
    ā””ā”€ā”€ index.scss
Enter fullscreen mode Exit fullscreen mode

Contributing

Who is for this? I would love for you to contribute to Angular Authentication! Before you start, please read the Contributor Guide.

If you have found any bug in the source code or want to request a new feature, you can help by submitting an issue at GitHub. Even better, you can fork this repository and submit a PR with the fix or the new feature description.

Support

  • Star this repository ā­ļø
  • Help it spread to a wider audience: Tweet

Author: Nikos Anifantis āœļø

  • Fullstack Software Engineer - Iā€™m currently working on Angular & Node.js application development.
  • I write stuff at dev.to/nikosanif and nikosanif.medium.com
  • How to reach me: Twitter LinkedIn

License

Feel free to use this repository, but please star and put a reference to this repository. šŸ™ ā¤ļø

MIT

Top comments (2)

Collapse
 
chiragshivam profile image
Chivi

That's very helpful, will definitely implement it

Thanks for sharing!

Collapse
 
nikosanif profile image
Nikos Anifantis

Thanks for your feedback! I am very happy to hear that! šŸ¤©