Skip to main content

Interface: Authorization

Collection of authentication and authorization utility methods. This interface provides access to core authentication functionality like signing in, signing out, retrieving user data, and managing password recovery.

Example

// Check if a user is currently logged in
window.mimeeqAuth.authorization.getUserData()
.then(user => {
if (user && !('name' in user)) {
console.log('User is logged in:', user);
} else {
console.log('No user is currently logged in');
}
});

Authentication

forgotPassword

forgotPassword: ForgotPassword

Initiates the password recovery process for a user account. This sends a verification code to the user's email address, which can then be used with forgotPasswordSubmit to reset their password.

Example

window.mimeeqAuth.authorization.forgotPassword('[email protected]')
.then(response => {
if (response.success) {
console.log('Password reset code sent! Check your email.');
// Show the code input field and new password fields
} else {
console.error('Failed to initiate password reset');
}
});

Param

Email address of the user account

Returns

A promise resolving to a success response or error information


forgotPasswordSubmit

forgotPasswordSubmit: ForgotPasswordSubmit

Completes the password recovery process by setting a new password with the verification code. After receiving the code from forgotPassword, the user can use this method to set a new password.

Example

window.mimeeqAuth.authorization.forgotPasswordSubmit(
'[email protected]',
'newSecurePassword123',
'123456'
).then(response => {
if (response.success) {
console.log('Password changed successfully!');
// Redirect to login page
} else {
console.error('Failed to reset password');
}
});

Param

Email address of the user account

Param

New password to set

Param

Verification code received via email

Returns

A promise resolving to a success response or error information


getToken

getToken: GetToken

Retrieves the authentication token for the current user session. This token can be used for authenticated API requests.

This method will only succeed if the user is currently authenticated.

Example

window.mimeeqAuth.authorization.getToken()
.then(token => {
if (token) {
// Use the token for authenticated API requests
fetch('https://api.example.com/data', {
headers: {
'Authorization': `Bearer ${token}`
}
});
} else {
console.log('No authenticated user found');
}
});

Returns

A promise resolving to the JWT token string or null if no user is authenticated


getUserData

getUserData: GetUserData

Retrieves the current user's data or session information. Use this method to check if a user is currently authenticated and to access their profile information.

This is useful for determining login state, personalizing UI elements, and checking permissions before performing authenticated operations.

Example

window.mimeeqAuth.authorization.getUserData()
.then((user) => {
if (user && !('name' in user)) {
// User is logged in
console.log(`Hello, ${user.firstName}!`);
// Update UI for logged-in state
} else {
// No user is logged in
// Show login button or redirect to login page
}
})
.catch((err) => {
console.error('Error checking authentication status:', err);
});

Returns

A promise that resolves to UserData when a user is authenticated, null when no user is authenticated, or AuthError on failure


resendSignUp

resendSignUp: ResendSignUp

Resends the sign-up confirmation code to the user's email. This is useful when a user didn't receive the original confirmation code or when the code has expired.

Example

window.mimeeqAuth.authorization.resendSignUp('[email protected]')
.then(response => {
if (response.success) {
console.log('Confirmation code has been resent to your email');
} else {
console.error('Failed to resend confirmation code');
}
});

Param

Email address of the user account

Fires

@mimeeq#mimeeq-resend-signup-confirm-code

Returns

A promise resolving to a success response or error information


signIn

signIn: SignIn

Signs in a user with the provided credentials. Authenticates the user against the specified customer and returns user data upon success.

Example

window.mimeeqAuth.authorization.signIn('[email protected]', 'password123', 'customer123')
.then(result => {
if ('name' in result) {
// Handle error
console.error(`Sign-in failed: ${result.message}`);
} else {
// Handle successful sign-in
console.log(`Welcome, ${result.firstName}!`);
}
});

Param

The username (email) to be signed in

Param

The password of the username

Param

ID of customer we want to sign in (optional)

Fires

@mimeeq#mimeeq-user-signed-in

Returns

A promise that resolves to UserData on success or AuthError on failure


signOut

signOut: SignOut

Signs out the current user from Mimeeq. This clears the current session and removes cached authentication data.

After signing out, the user will need to sign in again to access authenticated resources. It's recommended to reload the page after sign-out for a clean state.

Example

window.mimeeqAuth.authorization.signOut().then(() => {
window.location.reload();
});

Fires

@mimeeq#mimeeqRefreshSession

Fires

@mimeeq#mimeeq-user-signed-out

Returns

A promise that resolves to true on success or AuthError on failure