Skip to content

Commit b77e95b

Browse files
authored
feat(store): support NGXS state management (#10)
* refactor(store): isolate ngrx store from app logic via facades * chore(store): install and setup ngxs [WIP] * feat(store): implement `ngxs` as alternative store * chore: update packages * chore(app): standalone components by default
1 parent 69a5a11 commit b77e95b

40 files changed

Lines changed: 728 additions & 297 deletions

README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,33 @@ Live application: [angular-authentication.netlify.app](https://angular-authentic
3333
- [Node.js](https://nodejs.org/en/)
3434
- [Angular CLI](https://angular.io/cli)
3535

36-
### Setup & Usage
36+
### Setup & Local Development
3737

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

44+
### Use it as a Template
45+
46+
The main purpose of this repository is to provide a simple Angular application that demonstrates best practices for user authentication and authorization flows. The application is configured to use a fake API server (interceptor) that simulates the backend server. Also, it includes two state management libraries, NgRx and NGXS, so you can choose which one to use.
47+
48+
If you want to use this repository as a template for your project, you can follow these steps:
49+
50+
- Clone this repository
51+
- Remove fake API:
52+
- Delete `src/app/core/fake-api` folder
53+
- Remove all references from the `fake-api` folder
54+
- Remove the `fakeApiInterceptor` from `app.config.ts`
55+
- Choose the state management library you want to use:
56+
- NgRx: Remove `src/app/auth/store/ngxs` folder and the `index.ngxs.ts` file
57+
- NGXS: Remove `src/app/auth/store/ngrx` folder and the `index.ngrx.ts` file
58+
- Rename the `index.XXX.ts` file to `index.ts` in the `src/app/auth/store` folder
59+
- Update the `app.store.ts` file to import the correct store module
60+
- Remove all unused packages from `package.json`
61+
- Update the Google Analytics tracking ID by replacing `UA-XXXXX-Y` in the `index.html` file and in the `src/app/core/services/google-analytics.service.ts` file. Or remove the Google Analytics service if you don't want to use it.
62+
4463
### Useful Commands
4564

4665
- `npm start` - starts a dev server of Angular app
@@ -63,14 +82,16 @@ Live application: [angular-authentication.netlify.app](https://angular-authentic
6382
- Standalone Angular components
6483
- Angular Material UI components
6584
- Lazy loading of Angular components
66-
- API requests with `@ngrx/effects`
85+
- API requests with `@ngrx/effects` or `@ngxs/store` (you can choose at `src/app/app.config.ts`)
6786
- Responsive design
6887
- Custom In-memory Web API using interceptors
6988

7089
## Tech Stack
7190

7291
- [Angular](https://angular.io/)
73-
- [NgRX](https://ngrx.io/) - @ngrx/{store,effects,component}
92+
- State Management. This repos demonstrates **two** state management libraries, you can choose which one to use by following the instructions in the [Use it as a Template](#use-it-as-a-template) section.
93+
- [NgRX](https://ngrx.io/) - @ngrx/{store,effects,component}
94+
- [NGXS](https://www.ngxs.io/) - @ngxs/store
7495
- [Angular Material UI](https://material.angular.io/)
7596
- [Tailwind CSS](https://tailwindcss.com/)
7697
- Other dev tools
@@ -90,15 +111,20 @@ Below is the high-level structure of the application.
90111
│ ├── app.component.ts
91112
│ ├── app.config.ts
92113
│ ├── app.routes.ts
114+
│ ├── app.store.ts # configure store based on NgRx or NGXS
93115
│ │
94116
│ ├── auth # includes authentication logic
95117
│ │ ├── auth.routes.ts
96118
│ │ ├── auth.service.ts
97-
│ │ ├── guards
98119
│ │ ├── index.ts
120+
│ │ ├── guards
99121
│ │ ├── interceptors
100122
│ │ ├── login
101-
│ │ └── store
123+
│ │ ├── models
124+
│ │ ├── tokens
125+
│ │ └── store # Choose one of the following
126+
│ │ ├── ngrx # store based on NgRx
127+
│ │ └── ngxs # store based on NGXS
102128
│ │
103129
│ ├── core # includes core utilities
104130
│ │ ├── fake-api
@@ -139,7 +165,7 @@ If you have found any bug in the source code or want to _request_ a new feature,
139165
## Support
140166

141167
- Star this repository 👆⭐️
142-
- Help it spread to a wider audience: [![X](https://img.shields.io/twitter/url/https/x.com/nikosanif.svg?style=social&label=Tweet)](https://x.com/intent/tweet?text=An%20Angular%20application%20that%20demonstrates%20best%20practices%20for%20user%20authentication%20and%20authorization%20flows.%0A%0A%40nikosanif%20%0A%F0%9F%94%97%20https%3A%2F%2Fgithub.com%2Fnikosanif%2Fangular-authentication%0A%0A&hashtags=Angular,NgRx,MDX,tailwindcss,ngAuth)
168+
- Help it spread to a wider audience: [![X](https://img.shields.io/twitter/url/https/x.com/nikosanif.svg?style=social&label=Tweet)](https://x.com/intent/tweet?text=An%20Angular%20application%20that%20demonstrates%20best%20practices%20for%20user%20authentication%20and%20authorization%20flows.%0A%0A%40nikosanif%20%0A%F0%9F%94%97%20https%3A%2F%2Fgithub.com%2Fnikosanif%2Fangular-authentication%0A%0A&hashtags=Angular,NgRx,NGXS,MDX,tailwindcss,ngAuth)
143169

144170
### Author: Nikos Anifantis ✍️
145171

0 commit comments

Comments
 (0)