@@ -2,7 +2,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core';
2
2
import { LogoComponent } from '../../../common/components/logo/logo.component' ;
3
3
import { MatButton } from '@angular/material/button' ;
4
4
import { NullinsideTwitchBotService } from "../../../service/nullinside-twitch-bot.service" ;
5
- import { ActivatedRoute , ParamMap } from "@angular/router" ;
5
+ import { ActivatedRoute , ParamMap , Router } from "@angular/router" ;
6
6
import { Errors } from "../../login-landing/errors" ;
7
7
import { HttpErrorResponse } from "@angular/common/http" ;
8
8
import { NullinsideService } from "../../../service/nullinside.service" ;
@@ -13,6 +13,7 @@ import {MatCheckbox} from "@angular/material/checkbox";
13
13
import { TwitchBotFaqComponent } from "../twitch-bot-faq/twitch-bot-faq.component" ;
14
14
import { MatSnackBar } from "@angular/material/snack-bar" ;
15
15
import { FormsModule } from "@angular/forms" ;
16
+ import { Location } from "@angular/common" ;
16
17
17
18
@Component ( {
18
19
selector : 'app-twitch-bot-config' ,
@@ -41,6 +42,8 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
41
42
constructor ( private twitchBotApi : NullinsideTwitchBotService ,
42
43
private api : NullinsideService ,
43
44
private snackBar : MatSnackBar ,
45
+ private location : Location ,
46
+ private router : Router ,
44
47
private route : ActivatedRoute ) {
45
48
}
46
49
@@ -67,16 +70,30 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
67
70
return ;
68
71
}
69
72
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.
70
76
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 ;
78
80
}
79
81
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.
80
97
this . twitchBotApi . getIsMod ( ) . subscribe ( {
81
98
next : response => {
82
99
this . botIsMod = response . isMod ;
@@ -88,6 +105,7 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
88
105
}
89
106
} ) ;
90
107
108
+ // Get the person's existing configuration.
91
109
this . twitchBotApi . getConfig ( ) . subscribe ( {
92
110
next : response => {
93
111
this . botEnabled = response . isEnabled ;
0 commit comments