Skip to content

Commit 7dc6e40

Browse files
Forcing re-login for bookmarkers
Closes #32
1 parent c04e132 commit 7dc6e40

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {LogoComponent} from '../../../common/components/logo/logo.component';
33
import {MatButton} from '@angular/material/button';
44
import {NullinsideTwitchBotService} from "../../../service/nullinside-twitch-bot.service";
5-
import {ActivatedRoute, ParamMap} from "@angular/router";
5+
import {ActivatedRoute, ParamMap, Router} from "@angular/router";
66
import {Errors} from "../../login-landing/errors";
77
import {HttpErrorResponse} from "@angular/common/http";
88
import {NullinsideService} from "../../../service/nullinside.service";
@@ -13,6 +13,7 @@ import {MatCheckbox} from "@angular/material/checkbox";
1313
import {TwitchBotFaqComponent} from "../twitch-bot-faq/twitch-bot-faq.component";
1414
import {MatSnackBar} from "@angular/material/snack-bar";
1515
import {FormsModule} from "@angular/forms";
16+
import {Location} from "@angular/common";
1617

1718
@Component({
1819
selector: 'app-twitch-bot-config',
@@ -41,6 +42,8 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
4142
constructor(private twitchBotApi: NullinsideTwitchBotService,
4243
private api: NullinsideService,
4344
private snackBar: MatSnackBar,
45+
private location: Location,
46+
private router: Router,
4447
private route: ActivatedRoute) {
4548
}
4649

@@ -67,16 +70,30 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
6770
return;
6871
}
6972

73+
// Get the token, if there isn't one then they didn't get here by hitting the login button. Lets send them back
74+
// to the login page if that's the case. It'll help us keep people synced on updates the permissions we request
75+
// from their tokens.
7076
const token = params.get('token');
71-
if (token) {
72-
localStorage.setItem('auth-token', token);
73-
this.api.validateToken(token).subscribe({
74-
error: (_: HttpErrorResponse) => {
75-
this.onLoginFailed();
76-
}
77-
});
77+
if (!token) {
78+
this.router.navigate(['twitch-bot']);
79+
return;
7880
}
7981

82+
// Save the token and make sure its valid.
83+
localStorage.setItem('auth-token', token);
84+
this.api.validateToken(token).subscribe({
85+
error: (_: HttpErrorResponse) => {
86+
this.onLoginFailed();
87+
}
88+
});
89+
90+
// Kind of a workaround to remove the token from the query parameters in the url. The reason for this is
91+
// if someone wants to bookmark the page we don't want to leave that in there. A different site layout will
92+
// make this unnecessary.
93+
const url = this.router.createUrlTree([], {relativeTo: this.route}).toString();
94+
this.location.go(url);
95+
96+
// Check if the bot account is modded. If it isn't, we can offer to mod it.
8097
this.twitchBotApi.getIsMod().subscribe({
8198
next: response => {
8299
this.botIsMod = response.isMod;
@@ -88,6 +105,7 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
88105
}
89106
});
90107

108+
// Get the person's existing configuration.
91109
this.twitchBotApi.getConfig().subscribe({
92110
next: response => {
93111
this.botEnabled = response.isEnabled;

0 commit comments

Comments
 (0)