Skip to content

Commit

Permalink
Rename StravaAuthService to AuthService
Browse files Browse the repository at this point in the history
  • Loading branch information
m3nowak committed Oct 20, 2024
1 parent 968214b commit b848938
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Routes } from '@angular/router';
import { StravaAuthService } from './services/strava-auth.service';
import { AuthService } from './services/auth.service';
import { inject } from '@angular/core';
import { WelcomeScreenComponent } from './components/welcome-screen/welcome-screen.component';
import { RemoveQueryParamsGuard } from './guards/remove-query-params.guard';
Expand All @@ -13,7 +13,7 @@ export const routes: Routes = [
{
path: 'authorized',
redirectTo: ({ queryParams }) => {
const extAuthSvc = inject(StravaAuthService);
const extAuthSvc = inject(AuthService);
extAuthSvc.feedToken(queryParams);
return 'home';
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, inject } from '@angular/core';
import { StravaAuthService } from '../../services/strava-auth.service';
import { AuthService } from '../../services/auth.service';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

@Component({
Expand All @@ -10,5 +10,5 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
styleUrl: './login-purgatory.component.scss',
})
export class LoginPurgatoryComponent {
extAuthSvc = inject(StravaAuthService);
extAuthSvc = inject(AuthService);
}
4 changes: 2 additions & 2 deletions src/app/components/main-layout/main-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MapDisplayControlComponent } from '../map-display-control/map-display-c
import { MatSelectModule } from '@angular/material/select';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { StravaAuthService } from '../../services/strava-auth.service';
import { AuthService } from '../../services/auth.service';

@Component({
selector: 'app-main-layout',
Expand Down Expand Up @@ -41,7 +41,7 @@ export class MainLayoutComponent {
// shapeTypeControl = new FormControl('0');
routerSvc = inject(Router);
activatedRoute = inject(ActivatedRoute);
stravaAuthSvc = inject(StravaAuthService);
stravaAuthSvc = inject(AuthService);

fixFcSub: Subscription | undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/welcome-screen/welcome-screen.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { StravaAuthService } from '../../services/strava-auth.service';
import { AuthService } from '../../services/auth.service';
import { CustomNGXLoggerService } from 'ngx-logger';

@Component({
Expand All @@ -16,7 +16,7 @@ export class WelcomeScreenComponent {
partialConfig: { context: 'WelcomeScreen' },
});

stravaAuthSvc = inject(StravaAuthService);
stravaAuthSvc = inject(AuthService);

loginClick() {
this.logger.info('Login clicked');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';

import { StravaAuthService } from './strava-auth.service';
import { AuthService } from './auth.service';

describe('ExtAuthService', () => {
let service: StravaAuthService;
let service: AuthService;

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

it('should be created', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ import { computed, effect, inject, Injectable, signal } from '@angular/core';
import { Params, Router } from '@angular/router';
import { CustomNGXLoggerService } from 'ngx-logger';
import { environment } from '../../environments/environment';
import { AuthService } from '../api/services';
import { AuthService as ApiAuthService } from '../api/services';
import * as jose from 'jose';
import { DateTime } from 'luxon';

const TOKEN_KEY = 'authToken';

@Injectable({
providedIn: 'root',
})
export class StravaAuthService {
export class AuthService {
private loggerSvc = inject(CustomNGXLoggerService).getNewInstance({
partialConfig: { context: 'ExtAuth' },
});
authSvc = inject(AuthService);
authSvc = inject(ApiAuthService);
router = inject(Router);

currentToken = signal<string | undefined>(localStorage.getItem('stravaToken') ?? undefined);
currentToken = signal<string | undefined>(localStorage.getItem(TOKEN_KEY) ?? undefined);

localStorageEffect = effect(() => {
const token = this.currentToken();
if (token) {
localStorage.setItem('stravaToken', token);
localStorage.setItem(TOKEN_KEY, token);
} else {
localStorage.removeItem('stravaToken');
localStorage.removeItem(TOKEN_KEY);
}
});

Expand Down

0 comments on commit b848938

Please sign in to comment.