This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
generated from dalbitresb12/angular-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from futureleadersupc/feat/auth-service
feat(auth): added initial auth service
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface User { | ||
preferredName: string; | ||
fullName: string; | ||
email: string; | ||
location: string; | ||
profileViews: number; | ||
biography: string; | ||
about: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
|
||
import { AuthService } from "./auth.service"; | ||
|
||
describe("AuthService", () => { | ||
let service: AuthService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AuthService); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { User } from "../model/user"; | ||
import { Injectable } from "@angular/core"; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class AuthService { | ||
static user: User = { | ||
preferredName: "John", | ||
fullName: "John Doe", | ||
email: "john.doe@gmail.com", | ||
location: "Lima, Peru", | ||
profileViews: 367, | ||
biography: | ||
"Freelance UX/UI designer, 80+ projects in Web, Mobile (Android & iOS) and creative projects. Open to offers.", | ||
about: | ||
"I'm more experienced in e-commerce web projects and mobile banking apps, but also like to work with creative projects, such as landing pages or unusual corporate websites.", | ||
}; | ||
static loggedIn: boolean = true; | ||
|
||
constructor() {} | ||
|
||
static login(): void { | ||
this.loggedIn = true; | ||
} | ||
|
||
static logout(): void { | ||
this.loggedIn = false; | ||
} | ||
|
||
static getCurrentUser(): User | null { | ||
if (this.loggedIn) { | ||
return this.user; | ||
} | ||
return null; | ||
} | ||
} |