-
Notifications
You must be signed in to change notification settings - Fork 373
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
Incorrect typing on createUser
api in admin.auth leads to broken multi-factor auth
#1267
Comments
Relevant code from admin sdk is here firebase-admin-node/src/auth/index.ts Line 449 in d961c3f
extends firebase-admin-node/src/auth/index.ts Line 466 in d961c3f
|
Fixes firebase#1267. Derived classes are not interchangeable with Base classes as types. Rather than making the request take a generic `<T extends CreateMultifactorInfoRequest>`, this assigns a union of the (one currently allowed) type.
Thanks for raising this issue. I've noticed this problem in several places in our API. Here are some:
The proposed solution of using union types is probably the right approach. However, I'd also note that you don't need an const factor: admin.auth.CreatePhoneMultiFactorInfoRequest = {phoneNumber: '', factorId: 'phone'};
admin.auth().createUser({
multiFactor: {enrolledFactors: [factor]},
}); Or even an in-place cast: admin.auth().createUser({
multiFactor: {enrolledFactors: [
{phoneNumber: '', factorId: 'phone'} as CreatePhoneMultiFactorInfoRequest
]},
}); Regardless, it would be nice if we could just pass object literals to these APIs, and have them correctly typed by default. @bojeil-google wdyt? |
I think union types sound good.👍 |
How about rearranging our typings like this? export interface BaseCreateMultiFactorInfoRequest {
displayName?: string;
}
export interface CreatePhoneMultiFactorInfoRequest extends BaseCreateMultiFactorInfoRequest {
factorId: 'phone';
phoneNumber: string;
}
export type CreateMultiFactorInfoRequest = | CreatePhoneMultiFactorInfoRequest;
// Same for update types This also enforces that the |
I think that looks reasonable. |
[REQUIRED] Step 3: Describe the problem
Typescript types are incorrect for
CreateMultiFactorInfoRequest
andCreatePhoneMultiFactorInfoRequest
inadmin.auth.createUser
. I expect to be able to pass in a phone number but am not allowed by the type system. Instead, I have to cast the type asany
.Steps to reproduce:
This yields the error
You can work around this by casting the object to an
any
, but the type system is still wrong here.This was also raised in #1048 but for some reason that ticket was closed by the OP.
As a side-note, it feels like the code was written by someone who thought that extending a typescript
interface
would mean that instances of the derived class can be passed in instead of the base class, but with structural typing, this is not allowed.The text was updated successfully, but these errors were encountered: