Skip to content

Commit

Permalink
chore: refactor auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
ju4n97 committed Feb 3, 2021
1 parent ba0368b commit 7e1c7fa
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ Angular starter for enterprise-grade front-end projects, built under a clean arc
│ │ └───utils
│ ├───+auth
│ │ └───pages
│ │ ├───forgot-password
│ │ ├───forgot-password-email-sent
│ │ ├───password-reset
│ │ ├───password-reset-failed
│ │ ├───password-reset-succeeded
│ │ ├───sign-in
│ │ └───sign-up
│ │ | ├───forgot-password
│ │ | ├───forgot-password-email-sent
│ │ | ├───password-reset
│ │ | ├───password-reset-failed
│ │ | ├───password-reset-succeeded
│ │ | ├───sign-in
│ │ | └───sign-up
│ │ └───services
│ │ | └───auth.service
│ ├───+settings
│ │ └───pages
│ │ ├───account
Expand Down Expand Up @@ -156,6 +158,7 @@ Angular starter for enterprise-grade front-end projects, built under a clean arc
| Command | Description | NPM | Yarn | Background command |
| ------------ | ------------------------------------------------ | ------------------ | --------------- | --------------------------------------------------------------- |
| ng | See available commands | npm run ng | yarn ng | ng |
| dev | Run your app in development mode & open app | npm run dev | yarn dev | ng serve -o |
| start | Run your app in development mode | npm start | yarn start | ng serve |
| start:es | Run your app in development mode in spanish | npm run start:es | yarn start:es | ng serve -c=es --port 4201 |
| build | Build your app | npm run build | yarn build | ng build |
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"ng": "ng",
"dev": "ng serve -o",
"start": "ng serve",
"start:es": "ng serve -c=es --port 4201",
"build": "ng build",
Expand Down Expand Up @@ -56,9 +57,9 @@
"@types/node": "^14.14.22",
"@typescript-eslint/eslint-plugin": "4.14.2",
"@typescript-eslint/parser": "4.14.2",
"codelyzer": "^6.0.1",
"codelyzer": "^6.0.1",
"eslint-plugin-jsdoc": "31.6.0",
"eslint": "^7.19.0",
"eslint": "^7.19.0",
"eslint-plugin-prefer-arrow": "1.2.3",
"husky": "^4.3.8",
"jasmine-core": "~3.6.0",
Expand Down
13 changes: 8 additions & 5 deletions src/app/+auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class AuthService {
isLoggedIn$ = new BehaviorSubject<boolean>(!!this.getToken());

constructor() { }
constructor() {}

get isLoggedIn(): boolean {
return this.isLoggedIn$.getValue();
}

signIn(): void {
this.storeToken();
const token = Array(4)
.fill(0)
.map((_) => Math.random() * 99)
.join('-');
this.storeToken(token);
this.isLoggedIn$.next(true);
}

Expand All @@ -27,8 +31,7 @@ export class AuthService {
return localStorage.getItem('token');
}

private storeToken(): void {
const token = 'ABC';
private storeToken(token: string): void {
localStorage.setItem('token', token);
}

Expand Down
16 changes: 16 additions & 0 deletions src/app/@core/services/seo/seo.service.spect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { SeoService } from './Seo.service';


describe('SeoService', () => {
let service: SeoService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SeoService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
6 changes: 5 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { Path } from './@core/structs';
export class AppComponent implements OnInit {
isLoggedIn$: Observable<boolean>;

constructor(private router: Router, private seoService: SeoService, private authService: AuthService) {}
constructor(
private router: Router,
private seoService: SeoService,
private authService: AuthService
) {}

ngOnInit(): void {
this.isLoggedIn$ = this.authService.isLoggedIn$;
Expand Down

0 comments on commit 7e1c7fa

Please sign in to comment.