Twitch login, TTS Login, and basic policies ui.
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TwitchAuthCallbackComponent } from './twitch-auth-callback.component';
|
||||
|
||||
describe('TwitchAuthCallbackComponent', () => {
|
||||
let component: TwitchAuthCallbackComponent;
|
||||
let fixture: ComponentFixture<TwitchAuthCallbackComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TwitchAuthCallbackComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TwitchAuthCallbackComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,48 @@
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ApiAuthenticationService } from '../shared/services/api/api-authentication.service';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Component({
|
||||
selector: 'app-twitch-auth-callback',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './twitch-auth-callback.component.html',
|
||||
styleUrl: './twitch-auth-callback.component.scss'
|
||||
})
|
||||
export class TwitchAuthCallbackComponent implements OnInit {
|
||||
private isBrowser: boolean;
|
||||
|
||||
constructor(private http: HttpClient, private auth: ApiAuthenticationService, private route: ActivatedRoute, private router: Router, @Inject(PLATFORM_ID) private platformId: Object) {
|
||||
this.isBrowser = isPlatformBrowser(this.platformId)
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (!this.isBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
const code = this.route.snapshot.queryParamMap.get('code');
|
||||
const scope = this.route.snapshot.queryParamMap.get('scope');
|
||||
const state = this.route.snapshot.queryParamMap.get('state');
|
||||
|
||||
console.log('twitch callback', code, scope, state);
|
||||
if (!code || !scope || !state)
|
||||
return;
|
||||
|
||||
this.http.post(environment.API_HOST + '/auth/twitch/callback', { code, scope, state })
|
||||
.subscribe((data: any) => {
|
||||
console.log('twitch callback response', code, scope, state, data);
|
||||
if (!data?.authenticated) {
|
||||
this.router.navigate(['/login?error=callback_error']);
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem('jwt', data.token);
|
||||
this.auth.update();
|
||||
this.router.navigate(['/tts-login']);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user