Before loading page in connect add-on I need to get user details using rest api.
Case 1:
When I have two pages I can get details from first page and pass to second page as arguments successfully.
In script file
// Get user timezone
AP.user.getTimeZone(function(timezone){
outerObj.userTimezone = timezone;
});
// Get user locale
AP.user.getLocale(function(locale){
outerObj.userLocale =locale;
});
$("#btnRedirect").on('click', function(e){
AP.navigator.go('addonModule', { addonKey: addon_key, moduleKey: module_key, customData: {tz: outerObj.userTimezone, loc: outerObj.userLocale}});
});
In router file
app.get('/secondpage', addon.authenticate(), (req, res) => {
var timezone = res.locals.timezone, locale = res.locals.locale,
res.setHeader('Access-Control-Allow-Origin','*');
res.render('secondpage', { title: 'Atlassian Connect', Timezone: timezone, Locale: locale });
});
Case2:
But, with single page I couldn’t get the user details(timezone and locale).
How to access AP.request in router file(index.js) before the page loads. So, I can pass the user timzezone and locale as arguments when redirecting to the hbs template file?
Here is the sample code that is used for redirecting in router file(index.js)
app.get('/hello-world', addon.authenticate(), (req, res) => {
res.setHeader('Access-Control-Allow-Origin','*');
res.render('hello-world', { title: 'Atlassian Connect' });
});