Stateful React API
Usage
The APIs and states are available by using the using the frontegg rest-api are exposed via promises and interfaces such as the below:
import { someApi } from "@frontegg/rest-api";
await someApi();
Authentication APIs
Pre-login
import { preLogin } from '@frontegg/rest-api';
const redirectUrl = await preLogin({ email: 'john@doe.com' });
if (redirectUrl) {
}
Returns if the user needs to be redirected to SSO based on email domain
Login
import { login } from '@frontegg/rest-api';
const loginResponse: {
accessToken: string;
refreshToken: string;
expires: string;
expiresIn: number;
mfaRequired: boolean;
mfaToken?: string;
emailVerified?: boolean;
} = await login({ email, password });
Logs in the user using email and password and returns the JWT and refresh token.In case MFA is required the MFA token will be returned
Login with MFA
import { loginWithMfa } from '@frontegg/rest-api';
const loginResponse: {
accessToken: string;
refreshToken: string;
expires: string;
expiresIn: number;
mfaRequired: boolean;
mfaToken?: string;
emailVerified?: boolean;
} = await loginWithMfa({ mfaToken, value });
Verifies the login using MFA token and value and gets the JWT token and the refresh token back
Activate account
import { activateAccount } from '@frontegg/rest-api';
await activateAccount({ userId, token, password });
Activates the users' account using the user ID, the token and the users' new password
Accept invitation to tenant
import { acceptInvitation } from '@frontegg/rest-api';
await acceptInvitation({ userId, token });
Accepts invitation of user to a new tenant and makes the user as active on that tenant
Refresh token
import { refreshToken } from '@frontegg/rest-api';
const loginResponse: {
accessToken: string;
refreshToken: string;
expires: string;
expiresIn: number;
mfaRequired: boolean;
mfaToken?: string;
emailVerified?: boolean;
} = await refreshToken();
Refresh the current user authentication
Logout
import { logout } from '@frontegg/rest-api';
await logout();
Logs out the user and clears the refresh token
Forgot password
import { logout } from '@frontegg/rest-api';
await logout();
Logs out the user and clears the refresh token
Reset password
import { resetPassword } from '@frontegg/rest-api';
await logout({
token,
userId,
password
});
Resets password based on token received from the forgot password flow
Recover MFA token
Allows the user to recover the MFA token
import { recoverMfaToken } from '@frontegg/rest-api';
await recoverMfaToken({
email,
recoveryCode
});