Skip to content

Commit 14e1e38

Browse files
refactor: make getWorkflow sync & throw
1 parent a41846d commit 14e1e38

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"global"
8888
],
8989
"@typescript-eslint/no-explicit-any": "off",
90+
"@typescript-eslint/require-await": "off",
9091
"no-restricted-imports": [
9192
"error",
9293
{
@@ -228,6 +229,7 @@
228229
"@typescript-eslint/no-unsafe-call": "off",
229230
"@typescript-eslint/restrict-plus-operands": "off",
230231
"@typescript-eslint/restrict-template-expressions": "off",
232+
"@typescript-eslint/require-await": "off",
231233
"no-return-await": "off",
232234
"@typescript-eslint/return-await": [
233235
"error",

src/cmap/auth/mongodb_oidc.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,8 @@ export class MongoDBOIDC extends AuthProvider {
8888
return callback(new MongoMissingCredentialsError('AuthContext must provide credentials.'));
8989
}
9090

91-
getWorkflow(credentials, (error, workflow) => {
92-
if (error) {
93-
return callback(error);
94-
}
95-
if (!workflow) {
96-
return callback(
97-
new MongoRuntimeError(
98-
`Could not load workflow for device ${credentials.mechanismProperties.PROVIDER_NAME}`
99-
)
100-
);
101-
}
91+
try {
92+
const workflow = getWorkflow(credentials);
10293
workflow.execute(connection, credentials, reauthenticating).then(
10394
result => {
10495
return callback(undefined, result);
@@ -107,7 +98,9 @@ export class MongoDBOIDC extends AuthProvider {
10798
callback(error);
10899
}
109100
);
110-
});
101+
} catch (error) {
102+
callback(error);
103+
}
111104
}
112105

113106
/**
@@ -150,15 +143,13 @@ export class MongoDBOIDC extends AuthProvider {
150143
/**
151144
* Gets either a device workflow or callback workflow.
152145
*/
153-
function getWorkflow(credentials: MongoCredentials, callback: Callback<Workflow>): void {
146+
function getWorkflow(credentials: MongoCredentials): Workflow {
154147
const providerName = credentials.mechanismProperties.PROVIDER_NAME;
155148
const workflow = OIDC_WORKFLOWS.get(providerName || 'callback');
156149
if (!workflow) {
157-
return callback(
158-
new MongoInvalidArgumentError(
159-
`Could not load workflow for provider ${credentials.mechanismProperties.PROVIDER_NAME}`
160-
)
150+
throw new MongoInvalidArgumentError(
151+
`Could not load workflow for provider ${credentials.mechanismProperties.PROVIDER_NAME}`
161152
);
162153
}
163-
callback(undefined, workflow);
154+
return workflow;
164155
}

0 commit comments

Comments
 (0)