|
1 | | ---- |
2 | | -# This repository is for version 2.x of the example application. |
3 | | -# [Click here for the latest version (4.x)](https://github.com/ngrx/platform) |
4 | | ---- |
5 | | - |
6 | | -# @ngrx example application |
7 | | - |
8 | | -Example application utilizing @ngrx libraries, showcasing common patterns and best practices. |
9 | | -Take a look at the [live app](http://ngrx.github.io/example-app/). |
10 | | - |
11 | | -This app is a book collection manager. Using the Google Books API, the user can search for |
12 | | -books and add them to their collection. This application utilizes [@ngrx/db](https://github.com/ngrx/db) |
13 | | -to persist the collection across sessions; [@ngrx/store](https://github.com/ngrx/store) to manage |
14 | | -the state of the app and to cache requests made to the Google Books API; |
15 | | -[@angular/router](https://github.com/angular/angular) to manage navigation between routes; |
16 | | -[@ngrx/effects](https://github.com/ngrx/effects) to isolate side effects. |
17 | | - |
18 | | -Built with [@angular/cli](https://github.com/angular/angular-cli) |
19 | | - |
20 | | -### Included |
21 | | - - [ngrx/store](https://github.com/ngrx/store) - RxJS powered state management for Angular apps, inspired by Redux |
22 | | - - [ngrx/effects](https://github.com/ngrx/effects) - Side effect model for @ngrx/store |
23 | | - - [angular/router](https://github.com/angular/angular) - Angular Router |
24 | | - - [ngrx/db](https://github.com/ngrx/db) - RxJS powered IndexedDB for Angular apps |
25 | | - - [ngrx/store-devtools](https://github.com/ngrx/store-devtools) - Instrumentation for @ngrx/store enabling time-travel debugging |
26 | | - - [codewareio/ngrx-store-freeze](https://github.com/codewareio/ngrx-store-freeze) - A @ngrx/store meta reducer that prevents state from being mutated |
27 | | - - [reselect](https://github.com/reactjs/reselect) - Selector library for Redux |
28 | | - |
29 | | -### Quick start |
30 | | - |
31 | | -```bash |
32 | | -# clone the repo |
33 | | -git clone https://github.com/ngrx/example-app.git |
34 | | - |
35 | | - |
36 | | -# change directory to repo |
37 | | -cd example-app |
38 | | - |
39 | | -# Use npm or yarn to install the dependencies: |
40 | | -npm install |
41 | | - |
42 | | -# OR |
43 | | -yarn |
44 | | - |
45 | | -# start the server |
46 | | -ng serve |
| 1 | +# CloudNC Angular Interview Challenge |
| 2 | +(Fork of https://github.com/ngrx/example-app) |
| 3 | + |
| 4 | +## The Challenge |
| 5 | +Starting with the "Books" demo application for ngrx, add authenticated |
| 6 | +protection to the application so a user cannot access books or |
| 7 | +collections without valid credentials. |
| 8 | + |
| 9 | +## Details |
| 10 | +* The following components should be protected |
| 11 | +(these are components that currenly have routes) |
| 12 | + * `CollectionPageComponent` - as this is currently the root route (`path: ''`) |
| 13 | + it should be moved to `/collection` |
| 14 | + * `FindBookPageComponent` |
| 15 | + * `ViewBookPageComponent` |
| 16 | +* If a user attempts to access a protected route, they should be |
| 17 | +redirected to the login page |
| 18 | +* Once the user is logged in, they should see the phrase |
| 19 | +`Logged In as ${username}` in the toolbar |
| 20 | +* If the user is logged in, and they load the `/` route, they should be |
| 21 | +redirected to the `/collection` page |
| 22 | +* The authentication service should simply be a stub that checks if the |
| 23 | +submitted password is `password`. For example: |
| 24 | +```ts |
| 25 | + /** |
| 26 | + * Asynchronously authenticate with a remote service |
| 27 | + * @todo(*) actually authenticate |
| 28 | + */ |
| 29 | + public authenticate(username: string, password: string): Observable<boolean> { |
| 30 | + |
| 31 | + if (password === 'password') { |
| 32 | + console.info(`Logged in as ${username}`); |
| 33 | + return Observable.of(true); |
| 34 | + } |
| 35 | + |
| 36 | + console.info(`Access denied for ${username} (Incorrect password)`); |
| 37 | + |
| 38 | + return Observable.of(false); |
| 39 | + } |
47 | 40 | ``` |
48 | | - |
49 | | -Navigate to [http://localhost:4200/](http://localhost:4200/) in your browser |
50 | | - |
51 | | -_NOTE:_ The above setup instructions assume you have added local npm bin folders to your path. |
52 | | -If this is not the case you will need to install the Angular CLI globally. |
| 41 | +* The login state should be persisted to the browser database |
| 42 | +(see `src/app/effects/collection.ts` for an example) so page refreshes |
| 43 | +result in the user still being logged in |
| 44 | +* If the user attempts to visit a protected page, after they are |
| 45 | +redirected AND successfully log in, they should be redirected back to |
| 46 | +the page that they were first attempting to visit |
| 47 | +
|
| 48 | +# Bonus! (if time allows) |
| 49 | +* Write tests for the service/guard/reducer/component |
0 commit comments