Skip to content

Commit 0b06022

Browse files
feat: updating desktop login page to coencide with new login flow
1 parent 9b2399c commit 0b06022

File tree

4 files changed

+27
-98
lines changed

4 files changed

+27
-98
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum Errors {
2+
NO_ERROR,
3+
INTERNAL_ERROR,
4+
TWITCH_FAILED_TO_GENERATE_TOKEN
5+
}

src/src/app/view/login-landing-desktop/login-landing-desktop.component.html

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,12 @@
33
<app-logo/>
44
</div>
55
<div class="centered-box_content-container">
6-
@if (loggedIn) {
7-
<h2>LOGGED IN SUCCESSFULLY!</h2>
8-
<p>Please return to the desktop application...</p>
9-
<button mat-stroked-button color="primary" (click)="window.close()">
10-
Close
11-
</button>
12-
} @else if (loading) {
13-
<app-loading-icon fontSize="24px" height="35px" width="35px">Logging in</app-loading-icon>
6+
@if (error !== '') {
7+
<div class="error-banner">{{ error }}, please try again</div>
148
} @else {
15-
@if (error !== '') {
16-
<div class="error-banner">{{ error }}</div>
17-
} @else {
18-
@if (null !== oAuth) {
19-
<h2>DO NOT SHOW ON STREAM</h2>
20-
<button mat-stroked-button color="primary" [cdkCopyToClipboard]="JSON.stringify(oAuth)">Copy to
21-
Clipboard
22-
</button>
23-
} @else {
24-
<div class="error-banner">Failed to get you authenticated, please try again</div>
25-
}
26-
}
9+
<div class="info-banner">Login was successful!</div>
10+
<div class="instructions">Please return to the desktop application :)</div>
11+
<div class="sub-instructions">You can close this window</div>
2712
}
2813
</div>
2914
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.instructions {
2+
font-size: 25px;
3+
margin-top: 10px;
4+
}
5+
6+
.sub-instructions {
7+
font-size: 18px;
8+
margin-top: 10px;
9+
}
Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,45 @@
11
import {Component, inject, OnInit} from '@angular/core';
22
import {ActivatedRoute, ParamMap} from "@angular/router";
3-
import {Errors} from "../login-landing/errors";
3+
import {Errors} from "./errors";
44
import {HttpErrorResponse} from "@angular/common/http";
5-
import {LoadingIconComponent} from "../../common/components/loading-icon/loading-icon.component";
65
import {LogoComponent} from "../../common/components/logo/logo.component";
7-
import {OAuth} from "../../common/interface/oauth";
8-
import {MatButton} from "@angular/material/button";
9-
import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
10-
import {interval, Subscription} from "rxjs";
116

127
@Component({
138
selector: 'app-login-landing-desktop',
149
imports: [
15-
LoadingIconComponent,
16-
LogoComponent,
17-
MatButton,
18-
CdkCopyToClipboard
10+
LogoComponent
1911
],
2012
templateUrl: './login-landing-desktop.component.html',
2113
styleUrl: './login-landing-desktop.component.scss'
2214
})
2315
export class LoginLandingDesktopComponent implements OnInit {
2416
private route = inject(ActivatedRoute);
25-
private timer: Subscription | undefined;
26-
private desktopData: string | undefined;
2717

28-
loggedIn: boolean = false;
2918
error: string = '';
30-
oAuth: OAuth | null = null;
31-
loading: boolean = true;
3219

3320
ngOnInit(): void {
3421
this.route.queryParamMap.subscribe({
3522
next: (params: ParamMap) => {
23+
// Handle any errors
3624
const error = params.get('error');
3725
if (null !== error) {
3826
const errorNum = +error;
39-
if (Errors.TWITCH_ACCOUNT_HAS_NO_EMAIL === errorNum) {
40-
this.onLoginFailed('Your Twitch account must have a valid e-mail address, please add one and try again')
41-
} else if (Errors.TWITCH_ERROR_WITH_TOKEN === errorNum) {
42-
this.onLoginFailed('Twitch failed to give us a valid token, please try again')
43-
} else {
44-
this.onLoginFailed('Sorry we did something wrong trying to log you in, please try again')
27+
if (Errors.INTERNAL_ERROR === errorNum) {
28+
this.onLoginFailed()
29+
} else if (Errors.TWITCH_FAILED_TO_GENERATE_TOKEN === errorNum) {
30+
this.onLoginFailed('Received error from twitch, it may be down temporarily')
4531
}
4632

4733
return;
4834
}
49-
50-
const oAuth = {
51-
bearer: params.get('bearer'),
52-
refresh: params.get('refresh'),
53-
expiresUtc: params.get('expiresUtc'),
54-
};
55-
56-
if (null === oAuth.bearer || null === oAuth.refresh || null === oAuth.expiresUtc) {
57-
this.onLoginFailed();
58-
return;
59-
}
60-
61-
this.oAuth = {
62-
bearer: oAuth.bearer,
63-
refresh: oAuth.refresh,
64-
expiresUtc: oAuth.expiresUtc
65-
};
66-
67-
// DO NOT assign this.desktopData until AFTER you update the clipboard successfully.
68-
// The absence of a value on this.desktopData is what tells the application we haven't logged in yet.
69-
const json = JSON.stringify(oAuth);
70-
navigator.clipboard.writeText(json);
71-
this.desktopData = json;
72-
73-
this.loading = false;
74-
this.timer = interval(1000)
75-
.subscribe({
76-
next: _ => {
77-
this.runCheckForLogin();
78-
},
79-
error: e => {
80-
console.error(e);
81-
}
82-
});
8335
},
8436
error: (_: HttpErrorResponse) => {
8537
this.onLoginFailed();
8638
}
8739
});
8840
}
8941

90-
private runCheckForLogin() {
91-
try {
92-
navigator.clipboard.readText().then(text => {
93-
// If the text matches what we put on the clipboard then we aren't signed in yet.
94-
if (undefined === this.desktopData || text === this.desktopData) {
95-
return;
96-
}
97-
98-
// If the text does match, we are signed in on the desktop app. Maybe...kinda....might be...you never know...
99-
// Don't judge me. -.-
100-
this.timer?.unsubscribe();
101-
this.loggedIn = true;
102-
})
103-
} catch {
104-
// Do nothing, just don't crash.
105-
}
106-
}
107-
108-
onLoginFailed(message = ':( Failed to login, please try again'): void {
42+
onLoginFailed(message = 'Internal error logging you in'): void {
10943
this.error = message;
110-
this.loading = false;
11144
}
112-
113-
protected readonly JSON = JSON;
114-
protected readonly window = window;
11545
}

0 commit comments

Comments
 (0)