Post-Login Action Not Setting App_Metadata
Last Updated:
Overview
Below is the code snippet that is attempting to set the app_metadata.
fetch(path, options)
.then((response) => {[...]
}).then((body) => { if ( <some condition>) {
api.user.setAppMetadata("key", "value");
return; }
What is the reason for this unexpected behavior, and how can it be resolved?
Cause
fetch(path, options)
.then((response) => {[...]
}).then((body) => { if ( <some condition>) {
api.user.setAppMetadata("key", "value");
return; }
When calling this method inside the fetch request, it does not work. This Post-Login Action does not have the context to execute that method when in a fetch request.Solution
Execute the method 'api.user.setAppMetadata("key", "value")' outside of the fetch().then() clause to resolve this issue. For example:
...
fetch(path, options)
.then((response) => {[...]
}).then((body) => { if ( <some condition>) {
//execute custom code as needed
return; }
//outside of the above fetch request this method can now be called as expected
api.user.setAppMetadata("key", "value");
...