Skip to content

Commit 64dc844

Browse files
committed
Store authnMethod from init
1 parent b588203 commit 64dc844

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

docs/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,17 @@ These common options are used in multiple APIs. Instead of repeating the same op
331331

332332
<strong>NOTE:</strong> Since `options` are optional for each function call in the SDK, they will be read from the [init options](?id=api-init_options) by default if none are provided.
333333

334-
| Parameter | Type | Required | Default Value | Description |
335-
| ----------------------------------------------------------------- | ------------------------------------------ | -------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
336-
| options.email | string | false | Value set during `init`. | Email used to pre-fill the email field in login or sign up or form. |
337-
| options.backTo | string | false | Value set during `init`. | A redirection URL for redirecting a guest back to in the following condition: <li>Guest clicks on `Back to [App Name]` button in any Moneytree screen.</li><li>Guest refuses to give consent to access permission in the consent screen.</li><li>Guest logs out from Moneytree via an app with this client id</li><li>Revoke an app's consent from settings screen opened via an app with this client id</li><br /><br /><strong>NOTE:</strong> No `Back to [App Name]` button will be shown if this value is not set, and any of the actions mentioned above will redirect the guest back to login screen by default. |
338-
| <span id="authorize_option_auth_action">options.authAction</span> | `login`, `signup` | false | Value set during `init`.<p><strong>OR</strong></p>`login` | Show login or sign up screen when a session does not exist during an `authorize` call. |
339-
| options.showAuthToggle | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the login to sign up form toggle button and vice-versa in the auth screen, set this to `false`. |
340-
| options.showRememberMe | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the `Stay logged in for 30 days` checkbox in the login screen, set this to `false`. w |
341-
| options.isNewTab | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`false` | Call method and open/render in a new browser tab, by default all views open in the same tab. |
342-
| options.authnMethod | string <p><strong>OR</strong></p> string[] | | Value set during `init`. | Use different authentication methods. This can be a string or an array of the following values:<br /><br />`sso`, `passwordless`. |
343-
| options.sdkPlatform (private) | string | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk platform. |
344-
| options.sdkVersion (private) | semver | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk version. |
334+
| Parameter | Type | Required | Default Value | Description |
335+
| ----------------------------------------------------------------- | ----------------- | -------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
336+
| options.email | string | false | Value set during `init`. | Email used to pre-fill the email field in login or sign up or form. |
337+
| options.backTo | string | false | Value set during `init`. | A redirection URL for redirecting a guest back to in the following condition: <li>Guest clicks on `Back to [App Name]` button in any Moneytree screen.</li><li>Guest refuses to give consent to access permission in the consent screen.</li><li>Guest logs out from Moneytree via an app with this client id</li><li>Revoke an app's consent from settings screen opened via an app with this client id</li><br /><br /><strong>NOTE:</strong> No `Back to [App Name]` button will be shown if this value is not set, and any of the actions mentioned above will redirect the guest back to login screen by default. |
338+
| <span id="authorize_option_auth_action">options.authAction</span> | `login`, `signup` | false | Value set during `init`.<p><strong>OR</strong></p>`login` | Show login or sign up screen when a session does not exist during an `authorize` call. |
339+
| options.showAuthToggle | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the login to sign up form toggle button and vice-versa in the auth screen, set this to `false`. |
340+
| options.showRememberMe | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`true` | If you wish to disable the `Stay logged in for 30 days` checkbox in the login screen, set this to `false`. w |
341+
| options.isNewTab | boolean | false | Value set during `init`.<p><strong>OR</strong></p>`false` | Call method and open/render in a new browser tab, by default all views open in the same tab. |
342+
| options.authnMethod | string | | Value set during `init`. | Use different authentication methods. This can be a string with the following values:<br /><br />`sso`, `passwordless`, `credentials`. |
343+
| options.sdkPlatform (private) | string | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk platform. |
344+
| options.sdkVersion (private) | semver | false | Generated by the SDK. | <strong>NOTE: this is for Moneytree internal use, please do not use it to avoid unintended behavior!</strong><br /><br />Indicating sdk version. |
345345

346346
## Theming
347347

src/__tests__/helper.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ describe('helper', () => {
2424
backTo: 'backTo',
2525
authAction: 'signup',
2626
showAuthToggle: true,
27-
showRememberMe: true
27+
showRememberMe: true,
28+
authnMethod: 'sso'
2829
},
2930
{}
3031
)
31-
).toMatchObject({
32+
).toEqual({
33+
authAction: 'signup',
3234
email: 'email',
3335
backTo: 'backTo',
34-
authAction: 'signup',
36+
showRememberMe: true,
3537
showAuthToggle: true,
36-
showRememberMe: true
38+
authnMethod: 'sso'
3739
});
3840
});
3941

@@ -74,13 +76,14 @@ describe('helper', () => {
7476
showAuthToggle: true,
7577
showRememberMe: true,
7678
// @ts-ignore: set unsupported key
77-
whatIsThis: false
79+
whatIsThis: false,
80+
authnMethod: 'not really valid' as AuthnMethod
7881
},
7982
{
8083
whatIsThis2: false
8184
}
8285
)
83-
).toMatchObject({
86+
).toEqual({
8487
email: 'email',
8588
backTo: 'backTo',
8689
authAction: 'signup',

src/helper.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
AuthAction,
1515
AuthnMethod,
1616
supportedAuthnMethod,
17-
supportedAuthAction
17+
supportedAuthAction,
18+
supportedConfigsOptions,
19+
SupportedConfigsOptions
1820
} from './typings';
1921

2022
export function constructScopes(scopes: Scopes = ''): string | undefined {
@@ -35,7 +37,8 @@ export function mergeConfigs(
3537
backTo: defaultBackTo,
3638
authAction: defaultAuthAction,
3739
showAuthToggle: defaultShowAuthToggle,
38-
showRememberMe: defaultShowRememberMe
40+
showRememberMe: defaultShowRememberMe,
41+
authnMethod: defaultAuthnMethod
3942
} = initValues;
4043

4144
const {
@@ -44,27 +47,29 @@ export function mergeConfigs(
4447
authAction = defaultAuthAction,
4548
showAuthToggle = defaultShowAuthToggle,
4649
showRememberMe = defaultShowRememberMe,
50+
authnMethod: rawAuthnMethod = defaultAuthnMethod,
4751
...rest
4852
} = newValues;
4953

54+
const authnMethod = parseAuthnMethod(rawAuthnMethod);
55+
5056
const configs: ConfigsOptions = {
5157
...rest,
5258
email,
5359
backTo,
5460
authAction,
5561
showAuthToggle,
56-
showRememberMe
62+
showRememberMe,
63+
authnMethod
5764
};
5865

59-
if (ignoreKeys.length) {
60-
const keys = Object.keys(configs) as Array<keyof ConfigsOptions>;
66+
const keys = Object.keys(configs) as Array<SupportedConfigsOptions>;
6167

62-
for (let i = 0; i < keys.length; i++) {
63-
const key = keys[i];
68+
for (let i = 0; i < keys.length; i++) {
69+
const key = keys[i];
6470

65-
if (ignoreKeys.indexOf(key) !== -1) {
66-
configs[key] = undefined;
67-
}
71+
if (ignoreKeys.indexOf(key) !== -1 || !supportedConfigsOptions.includes(key)) {
72+
configs[key] = undefined;
6873
}
6974
}
7075

0 commit comments

Comments
 (0)