@earnaha/auth0-action-helper v1.3.19
AHA auth0 action helper
Create custom actions in auth0
- login auth0 account
- create a action: e.g.
actions
→Flows
→Login
→Add Action
→Build Custom
- initialize the action:
name = Post Login Trigger = Login / Post Login Runtime = Node 16
- click
Create
Add dependencies
- click the cube icon in the left side of codes
- click
Add Dependency
name = @earnaha/auth0-action-helper version = 1.0.21 or latest
- click
Create
Setup event secrets
- click the key icon in the left side of codes
- click
Add Secret
, input keys and values like below, and then clickCreate
for each one.- ENV = local, dev, test, stage, alpha, beta, gamma, prod, ...etc.
- SERVICE = any string to distinguish your sites or services.
- DOMAIN = https://subdomain.yourdomain.com (backend url, https required)
- ACCESS_KEY = the secret key to access your backend api, encode string more than 25 letters
- ACCESS_SALT = the secret salt to access your backend api, a number more than 10 digits
- AUTH0_DOMAIN =
Applications
→Applications
→Machine to Machine App
→Settings
→Basic Information
→Domain
- AUTH0_CLIENT_ID =
Applications
→Applications
→Machine to Machine App
→Settings
→Basic Information
→Client ID
- AUTH0_CLIENT_SECRET =
Applications
→Applications
→Machine to Machine App
→Settings
→Basic Information
→Client Secret
- SENTRY_DSN = the sentry dns for logging, a sentry account is required. (https://sentry.io/)
- SENTRY_TRACES_SAMPLE_RATE = the sentry trace setting. e.g. 0.1, 1.0, ...etc.
- SENTRY_LOGGER_LEVEL = the sentry logger level setting. e,g, debug, info, ...etc.
- LINK_ACCOUNT_TIME = YYYY-MM-DD, account created after this date, merge accounts if having the same email.
Code in actions
Post login
make an API in your backend side with the route /auth/v3/login to handle the signed in/up account data.
const AhaHelper = require('@earnaha/auth0-action-helper');
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
try {
console.log('onExecutePostLogin event=',JSON.stringify(event));
console.log('onExecutePostLogin api=',JSON.stringify(api));
const helper = new AhaHelper.PostLoginHelper(event.secrets);
const res = await helper.exec(event, api);
console.log('onExecutePostLogin res=',res);
} catch (e) {
const errMsg = e?.response?.data || e?.message || `${e}`;
console.error('onExecutePostLogin error=', errMsg);
throw e;
}
};
/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };
Post change password
make an API in your backend side with the route /auth/v3/refer/invitation/accept to handle the invitation acceptance things after the invited account signs in/up.
const AhaHelper = require('@earnaha/auth0-action-helper');
/**
* Handler that will be called during the execution of a PostChangePassword flow.
*
* @param {Event} event - Details about the user and the context in which the change password is happening.
* @param {PostChangePasswordAPI} api - Methods and utilities to help change the behavior after a user changes their password.
*/
exports.onExecutePostChangePassword = async (event, api) => {
try {
console.log('onExecutePostChangePassword event=',JSON.stringify(event));
console.log('onExecutePostChangePassword api=',JSON.stringify(api));
const helper = new AhaHelper.PostChangePasswordHelper(event.secrets);
const res = await helper.exec(event, api);
console.log('onExecutePostChangePassword res=',JSON.stringify(res));
} catch (e) {
const errMsg = e?.response?.data || e?.message || `${e}`;
console.error('onExecutePostChangePassword error=', errMsg);
throw e;
}
};
Post user registration
currently no further handling in the exec function.
const AhaHelper = require('@earnaha/auth0-action-helper');
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
* @param {PostUserRegistrationAPI} api - Methods and utilities to help change the behavior after a signup.
*/
exports.onExecutePostUserRegistration = async (event, api) => {
try {
console.log('onExecutePostUserRegistration event=',JSON.stringify(event));
console.log('onExecutePostUserRegistration api=',JSON.stringify(api));
const helper = new AhaHelper.PostUserRegistrationHelper(event.secrets);
const res = await helper.exec(event, api);
console.log('onExecutePostUserRegistration res=',JSON.stringify(res));
} catch (e) {
const errMsg = e?.response?.data || e?.message || `${e}`;
console.error('onExecutePostUserRegistration error=', errMsg);
throw e;
}
};
Pre user registration
currently no further handling in the exec function.
const AhaHelper = require('@earnaha/auth0-action-helper');
/**
* Handler that will be called during the execution of a PreUserRegistration flow.
*
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePreUserRegistration = async (event, api) => {
try {
console.log('onExecutePreUserRegistration event=',JSON.stringify(event));
console.log('onExecutePreUserRegistration api=',JSON.stringify(api));
const helper = new AhaHelper.PreUserRegistrationHelper(event.secrets);
const res = await helper.exec(event, api);
console.log('onExecutePreUserRegistration res=',res);
} catch (e) {
const errMsg = e?.response?.data || e?.message || `${e}`;
console.error('onExecutePreUserRegistration error=', errMsg);
throw e;
}
};
Deploy and test
12 months ago
1 year ago
12 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago