Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

refactor(auth): full rewrite of AuthService #17

Merged
merged 11 commits into from
May 24, 2022

Conversation

dalbitresb12
Copy link
Contributor

@dalbitresb12 dalbitresb12 commented May 18, 2022

What does it do

This PR is a full refactor of the AuthService so that it uses the HttpClient with fake logins from the mock API.

  • Move common service logic to BaseService
  • Implement HttpClient
  • Use the service in auth pages
  • Manage global state for the User

Usage

Add the AuthService wherever you need it to your constructor:

import { Component } from "@angular/core";
import { AuthService } from "../auth/services/auth.service";

@Component({
  selector: "app-sample",
  templateUrl: "./sample.component.html",
  styleUrls: ["./sample.component.css"],
})
export class SampleComponent {
  constructor(private authService: AuthService) {}
}

If you just need access to the User global state, please use the UseUser hook provided in src/app/auth/hooks/use-user.ts. You can see sample implementation of this hook in the Profile and SignIn component.

This pull request also provided the initial implementation of the generic BaseService, which will be used for any new services implemented in the app. It provided generic implementation of CRUD operations for basic services, with the ability to create custom logic on each service with those base operations. You can see sample implementations of this on AuthService and ProjectsService.

Why is it needed

We'll use fake logins currently, but once the backend is fully implemented, we'll just switch to that.

Related issue(s)/PR(s)

Initial implementation: #6.

@dalbitresb12 dalbitresb12 added refactor A rewrite of some part of the code scope: auth Changes related to authentication services labels May 18, 2022
@dalbitresb12 dalbitresb12 added this to the Sprint 3 milestone May 18, 2022
@dalbitresb12 dalbitresb12 self-assigned this May 18, 2022
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 18, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ce98520
Status: ✅  Deploy successful!
Preview URL: https://e73db3c3.waw-frontend-angular.pages.dev

View logs

@dalbitresb12 dalbitresb12 marked this pull request as draft May 18, 2022 11:14
* Pages that need access to the global User object must extend UseUser
* The hook provides the object on a User property
* Pages must implement OnInit and OnDestroy, which must call the provided methods
* Sample implementations: SignIn and Profile components
@dalbitresb12 dalbitresb12 marked this pull request as ready for review May 19, 2022 02:18
Copy link
Contributor

@AdrianAlzamoraG AdrianAlzamoraG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes

Copy link
Contributor

@VivianMPQ VivianMPQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed changes

@dalbitresb12 dalbitresb12 merged commit dd5e5b2 into main May 24, 2022
@dalbitresb12 dalbitresb12 deleted the refactor/auth-service-user branch May 24, 2022 20:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor A rewrite of some part of the code scope: auth Changes related to authentication services
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants