Skip to content

hasAccess

For use with Netlify Visual Editor only.

connector.hasAccess(fn)

Used to check whether the current user has the necessary permissions to update content in the data source. Netlify calls this method when a user opens a site in the visual editor.

Takes a function with an object as a parameter. The object contains the following property:

ParameterDescription
userContextObject with information about the current user.

The function must return a Promise that resolves an object with the following properties:

PropertyDescription
hasConnectionBoolean. Set to true if the current user has connected to the data source. Usually, the existence of the OAuth accessToken indicates that the user has a connection.
hasPermissionsBoolean. Set to true if the user’s accessToken allows them to perform create, update, and delete operations on the content within the data source.

If your data source does not have an OAuth integration with Netlify, you can return true for both values.

userContext

Object that contains information about the current user. Contains the following properties:

PropertyDescription
emailString representing the Netlify user’s email address.
nameString representing the Netlify user’s username.
sso(optional) Object containing other user-specific OAuth tokens for communicating with the data source.
userContextObject with information about the current user. If your connector has an OAuth integration with the visual editor, use the accessToken on this object to validate the user’s access.

Usage example

// If your data source does not have an OAuth integration with Netlify, you can return `true` for both values.
connector.hasAccess(async ({ userContext }) => {
return {
hasPermissions: true,
hasConnection: true,
};
});
// If your data source has an OAuth integration with Netlify
connector.hasAccess(async ({ userContext }) => {
// check if accessToken is set, otherwise the user did not connect
// the content source with Netlify using OAuth
if (!userContext?.accessToken) {
return {
hasConnection: false,
hasPermissions: false,
}
}
// check that user’s accessToken provides
// the necessary access to update the content
const apiClient = new CustomCMSAPIClient({
url: state.options.apiURL,
token: userContext.accessToken,
});
const hasPermissions = await apiClient.checkAccess()
return {
hasConnection: true,
hasPermissions: hasPermissions,
}
});

Got it!

Your feedback helps us improve our docs.