mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-30 05:18:13 +00:00
feat: implement two-factor authentication flow during sign-in and add utility hooks for configuration management
This commit is contained in:
26
libs/auth/src/lib/hooks/two-factor-request.ts
Normal file
26
libs/auth/src/lib/hooks/two-factor-request.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
type AccountConfig = { id: string; isMFARequired: boolean };
|
||||
|
||||
/**
|
||||
* Picks the request that persists the two-step verification setting.
|
||||
*
|
||||
* `set-my-config` only ever creates, and `iam.account_configurations` is unique
|
||||
* per user — so an existing record has to be updated through PUT. Getting this
|
||||
* backwards works exactly once and then fails on the unique constraint, which
|
||||
* is why the choice lives here, apart from the hook, with a test on it.
|
||||
*/
|
||||
export function twoFactorRequest(
|
||||
config: AccountConfig | undefined,
|
||||
isMFARequired: boolean,
|
||||
) {
|
||||
return config
|
||||
? {
|
||||
url: `/account-configurations/my-config/${config.id}`,
|
||||
method: "PUT" as const,
|
||||
body: { isMFARequired },
|
||||
}
|
||||
: {
|
||||
url: "/account-configurations/set-my-config",
|
||||
method: "POST" as const,
|
||||
body: { isMFARequired },
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user