我请求在Salesforce Marketing Cloud上对我的网页进行身份验证,身份验证必须只进行一次并存储.
我的问题是,当我请求身份验证和获取代码时,我收到两个请求,第一个请求成功,第二个请求错误.
问为什么我在REACTIVE JS上收到两个请求1useEffect
?我的组件是否加载了两次?
以下是我的代码:
useEffect(() => {
async function initialize() {
const params = await getParamsFromUrl();
if (params.code) {
await getTokenAndSaveToSession(params.code);
await fetchJourneyData(); // Renamed the function to make it clearer
} else {
console.log('There is no code in the params');
}
}
initialize();
}, []); // The empty dependency array ensures that the effect runs only once on mount
async function getTokenAndSaveToSession(code: string) {
try {
const authService = new AuthService();
const result = await authService.getToken(code);
sessionStorage.setItem('token', result.token);
sessionStorage.setItem('expiration', result.expiration.toString());
} catch (error) {
console.log(error);
}
}