Skip to content

Commit 66e5d6e

Browse files
committed
Show OIDC sign in errors more sensibly
1 parent a24d8e2 commit 66e5d6e

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/domain/RootViewModel.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,11 @@ export class RootViewModel extends ViewModel {
9090
this._showLogin({loginToken});
9191
}
9292
} else if (oidcCallback) {
93-
if (oidcCallback.error) {
94-
this._setSection(() => this._error = new Error(`OIDC error: ${oidcCallback.error}`));
95-
} else {
96-
this.urlRouter.normalizeUrl();
97-
if (this.activeSection !== "login") {
98-
this._showLogin({
99-
oidc: oidcCallback,
100-
});
101-
}
93+
this.urlRouter.normalizeUrl();
94+
if (this.activeSection !== "login") {
95+
this._showLogin({
96+
oidc: oidcCallback,
97+
});
10298
}
10399
}
104100
else {

src/domain/login/LoginViewModel.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ import { OIDCLoginMethod } from "../../matrix/login/OIDCLoginMethod.js";
3232
type Options = {
3333
defaultHomeserver: string;
3434
ready: ReadyFn;
35-
oidc?: { state: string, code: string };
35+
oidc?: SegmentType["oidc"];
3636
loginToken?: string;
3737
} & BaseOptions;
3838

3939
export class LoginViewModel extends ViewModel<SegmentType, Options> {
4040
private _ready: ReadyFn;
4141
private _loginToken?: string;
4242
private _client: Client;
43-
private _oidc?: { state: string, code: string };
43+
private _oidc?: SegmentType["oidc"];
4444
private _loginOptions?: LoginOptions;
4545
private _passwordLoginViewModel?: PasswordLoginViewModel;
4646
private _startSSOLoginViewModel?: StartSSOLoginViewModel;
@@ -139,7 +139,7 @@ export class LoginViewModel extends ViewModel<SegmentType, Options> {
139139
})));
140140
this.emitChange("completeSSOLoginViewModel");
141141
}
142-
else if (this._oidc) {
142+
else if (this._oidc?.success === true) {
143143
this._hideHomeserver = true;
144144
this._completeOIDCLoginViewModel = this.track(new CompleteOIDCLoginViewModel(
145145
this.childOptions(
@@ -151,6 +151,10 @@ export class LoginViewModel extends ViewModel<SegmentType, Options> {
151151
})));
152152
this.emitChange("completeOIDCLoginViewModel");
153153
}
154+
else if (this._oidc?.success === false) {
155+
this._hideHomeserver = false;
156+
this._showError(`Sign in failed: ${this._oidc.errorDescription ?? this._oidc.error} `);
157+
}
154158
else {
155159
void this.queryHomeserver();
156160
}

src/domain/navigation/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export type SegmentType = {
3838
state: string,
3939
} &
4040
({
41+
success: true,
4142
code: string,
4243
} | {
44+
success: false,
4345
error: string,
4446
errorDescription: string | null,
4547
errorUri: string | null ,
@@ -149,13 +151,15 @@ export function parseUrlPath(urlPath: string, currentNavPath: Path<SegmentType>,
149151
// This is a proper OIDC callback
150152
if (code) {
151153
segments.push(new Segment("oidc", {
154+
success: true,
152155
state,
153156
code,
154157
}));
155158
return segments;
156159
} else if (error) {
157160
segments.push(new Segment("oidc", {
158161
state,
162+
success: false,
159163
error,
160164
errorDescription: params.get("error_description"),
161165
errorUri: params.get("error_uri"),

0 commit comments

Comments
 (0)