Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
6bd06278
Unverified
Commit
6bd06278
authored
2 years ago
by
Diego Sampaio
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Regression: Add support for 2FA errors to `Meteor.callAsync` (#27767)
parent
9fa9661f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/meteor/app/2fa/client/overrideMeteorCall.ts
+28
-2
28 additions, 2 deletions
apps/meteor/app/2fa/client/overrideMeteorCall.ts
apps/meteor/client/lib/2fa/process2faReturn.ts
+44
-0
44 additions, 0 deletions
apps/meteor/client/lib/2fa/process2faReturn.ts
with
72 additions
and
2 deletions
apps/meteor/app/2fa/client/overrideMeteorCall.ts
+
28
−
2
View file @
6bd06278
import
{
Meteor
}
from
'
meteor/meteor
'
;
import
{
t
}
from
'
../../utils/client
'
;
import
{
process2faReturn
}
from
'
../../../client/lib/2fa/process2faReturn
'
;
import
{
process2faReturn
,
process2faAsyncReturn
}
from
'
../../../client/lib/2fa/process2faReturn
'
;
import
{
isTotpInvalidError
}
from
'
../../../client/lib/2fa/utils
'
;
const
{
call
}
=
Meteor
;
const
{
call
,
callAsync
}
=
Meteor
;
type
Callback
=
{
(
error
:
unknown
):
void
;
...
...
@@ -34,8 +34,34 @@ const callWithoutTotp = (methodName: string, args: unknown[], callback: Callback
});
});
const
callAsyncWithTotp
=
(
methodName
:
string
,
args
:
unknown
[])
=>
async
(
twoFactorCode
:
string
,
twoFactorMethod
:
string
):
Promise
<
unknown
>
=>
{
try
{
const
result
=
await
callAsync
(
methodName
,
...
args
,
{
twoFactorCode
,
twoFactorMethod
});
return
result
;
}
catch
(
error
:
unknown
)
{
if
(
isTotpInvalidError
(
error
))
{
throw
new
Error
(
twoFactorMethod
===
'
password
'
?
t
(
'
Invalid_password
'
)
:
t
(
'
Invalid_two_factor_code
'
));
}
throw
error
;
}
};
Meteor
.
call
=
function
(
methodName
:
string
,
...
args
:
unknown
[]):
unknown
{
const
callback
=
args
.
length
>
0
&&
typeof
args
[
args
.
length
-
1
]
===
'
function
'
?
(
args
.
pop
()
as
Callback
)
:
():
void
=>
undefined
;
return
callWithoutTotp
(
methodName
,
args
,
callback
)();
};
Meteor
.
callAsync
=
async
function
_callAsyncWithTotp
(
methodName
:
string
,
...
args
:
unknown
[]):
Promise
<
unknown
>
{
const
promise
=
callAsync
(
methodName
,
...
args
);
return
process2faAsyncReturn
({
promise
,
onCode
:
callAsyncWithTotp
(
methodName
,
args
),
emailOrUsername
:
undefined
,
});
};
This diff is collapsed.
Click to expand it.
apps/meteor/client/lib/2fa/process2faReturn.ts
+
44
−
0
View file @
6bd06278
...
...
@@ -76,3 +76,47 @@ export function process2faReturn({
},
});
}
export
async
function
process2faAsyncReturn
({
promise
,
onCode
,
emailOrUsername
,
}:
{
promise
:
Promise
<
unknown
>
;
onCode
:
(
code
:
string
,
method
:
string
)
=>
void
;
emailOrUsername
:
string
|
null
|
undefined
;
}):
Promise
<
unknown
>
{
// if the promise is rejected, we need to check if it's a 2fa error
return
promise
.
catch
((
error
)
=>
{
// if it's not a 2fa error, we reject the promise
if
(
!
isTotpRequiredError
(
error
)
||
!
hasRequiredTwoFactorMethod
(
error
))
{
throw
error
;
}
const
props
=
{
method
:
error
.
details
.
method
,
emailOrUsername
:
emailOrUsername
||
error
.
details
.
emailOrUsername
||
Meteor
.
user
()?.
username
,
};
assertModalProps
(
props
);
return
new
Promise
<
unknown
>
((
resolve
,
reject
)
=>
{
imperativeModal
.
open
({
component
:
TwoFactorModal
,
props
:
{
...
props
,
onConfirm
:
(
code
:
string
,
method
:
string
):
void
=>
{
imperativeModal
.
close
();
// once we have the code, we resolve the promise with the result of the `onCode` callback
resolve
(
onCode
(
method
===
'
password
'
?
SHA256
(
code
)
:
code
,
method
));
},
onClose
:
():
void
=>
{
imperativeModal
.
close
();
reject
(
new
Meteor
.
Error
(
'
totp-canceled
'
));
},
},
});
});
});
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment