Skip to content

Commit

Permalink
Merge pull request #2 from hurry-harry/hf-link-auth-api
Browse files Browse the repository at this point in the history
Leftover commit
  • Loading branch information
hurry-harry authored Jan 11, 2024
2 parents 457b804 + 84a0e72 commit ff9baa0
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/app/_shared/constants/spotify-url.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const SPOTIFY_MY_PROFILE: string = "https://api.spotify.com/v1/me";
export const SPOTIFY_MY_TOP_ITEMS: string = "https://api.spotify.com/v1/me/top";
export const SPOTIFY_ALBUMS: string = "https://api.spotify.com/v1/albums";
export const SPOTIFY_NEW_RELEASES: string = "browse/new-releases";


4 changes: 4 additions & 0 deletions src/app/_shared/enums/spotify.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum SpotifyTopItemCategories {
Artists = "artists",
Tracks = "tracks"
}
3 changes: 3 additions & 0 deletions src/app/_shared/models/environment.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Environment {
apiUrl: string;
}
15 changes: 15 additions & 0 deletions src/app/_shared/services/spotify.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HttpClient } from "@angular/common/http";
import { environment } from "../../../environments/environment";
import { Observable } from "rxjs";
import { Injectable } from "@angular/core";

@Injectable({ providedIn: 'root' })
export class SpotifyService {
constructor(
private http: HttpClient) { }

login(): Observable<any> {
console.log('login triggered');
return this.http.post(`${environment.apiUrl}/login`, {});
}
}
4 changes: 1 addition & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
test 3

<router-outlet></router-outlet>
<router-outlet></router-outlet>
37 changes: 33 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';
import { Component, Inject, PLATFORM_ID } from '@angular/core';
import { CommonModule, isPlatformBrowser } from '@angular/common';
import { Router, RouterOutlet } from '@angular/router';

@Component({
selector: 'app-root',
Expand All @@ -10,5 +10,34 @@ import { RouterOutlet } from '@angular/router';
styleUrl: './app.component.scss'
})
export class AppComponent {
title = 'spotify-taeyeon-shenanigans';
title: string = 'spotify-taeyeon-shenanigans';
authToken: string = "";
urlRawParams: string = "";
urlParams: string = "";

constructor(
private router: Router,
@Inject(PLATFORM_ID) protected platformId: Object
) {}


ngOnInit(): void {
if (isPlatformBrowser(this.platformId)) {
let url = window.location.href;
if (url.includes('?')) {
this.checkUrl(url);
}
}
}

checkUrl(url: string): void {
console.log("checkign url");
this.urlRawParams = url.split('?')[1];
this.urlParams = this.urlRawParams.split('#')[0];
if (this.urlParams == 'authorized=true') {
this.authToken = url.split('#')[1];
sessionStorage.setItem('token', this.authToken);
this.router.navigate(['./home']);
}
}
}
3 changes: 2 additions & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideHttpClient } from '@angular/common/http';

export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)]
providers: [provideRouter(routes), provideHttpClient()]
};
11 changes: 10 additions & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { Routes } from '@angular/router';
import { LoginComponent } from './components/login/login.component';
import { HomeComponent } from './components/home/home.component';
import { AuthorizedComponent } from './components/authorized/authorized.component';

export const routes: Routes = [];
export const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'home', component: HomeComponent },
{ path: 'authorized', component: AuthorizedComponent },

{ path: '**', redirectTo: '' }
];
5 changes: 5 additions & 0 deletions src/environments/environment.dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Environment } from "../app/_shared/models/environment.model";

export const environment: Environment = {
apiUrl: "http://localhost:8888/" // replace with whatever host provider for the server-side
}
5 changes: 5 additions & 0 deletions src/environments/environment.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Environment } from "../app/_shared/models/environment.model";

export const environment: Environment = {
apiUrl: "http://localhost:8888/"
}
5 changes: 5 additions & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Environment } from "../app/_shared/models/environment.model";

export const environment: Environment = {
apiUrl: "http://localhost:8888"
}

0 comments on commit ff9baa0

Please sign in to comment.