-
Notifications
You must be signed in to change notification settings - Fork 19
fix(auth): Skip login when using noop auth #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
20b5bba
to
3046a9d
Compare
@@ -199,7 +200,13 @@ export class LoginService { | |||
} | |||
|
|||
private completeAuthMethod(method: string): void { | |||
this.authMethod.next(method); | |||
const validMethod = method as AuthMethod; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can still end up broken :-)
If I modify the Cryostat backend so that the BasicAuthManager reports its authentication method as "Broken", then the string 'Broken'
will be passed into this function as method
. This happens at runtime, where the as AuthMethod
type cast means nothing (since this is only a TypeScript compile-time check). !!validMethod
will be true
because validMethod
is just method
which is a non-empty string, and so we call authMethod.next('Broken')
.
I think instead of a typecast like method as AuthMethod
, what you wanted was to try to reverse-map from the string to the enum, like so: https://stackoverflow.com/questions/43804805/check-if-value-exists-in-enum-in-typescript
let validMethod;
if (Object.values(AuthMethod).includes(method)) {
validMethod = method as AuthMethod;
} else {
validMethod = AuthMethod.UNKNOWN;
}
this.authMethod.next(validMethod);
this.authMethod.complete();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried moving the typecast before Object.values(AuthMethod).includes
to prevent the error below. Let me know what you think.
ERROR in src/app/Shared/Services/Login.service.tsx:204:44
TS2345: Argument of type 'string' is not assignable to parameter of type 'AuthMethod'.
202 | private completeAuthMethod(method: string): void {
203 | let validMethod;
> 204 | if (Object.values(AuthMethod).includes(method)) {
| ^^^^^^
Fixes #327
NoopAuthForm
automatically callsonSubmit
on first load. The user is immediately directed to the dashboard.