how to store list of oauth2 refresh tokens with different expiration time?

Viewed 82

In my client side application(vuejs) user can have multiple accounts with different access tokens and refresh tokens, so i save them as an array in local storage and cookie but when i store refresh tokens in one array in cookie i can't put different expiration time for each of them. how should i make this work? or any different idea to store multiple refresh tokens?

refresh tokens array:

refreshTokensList = [{ accountId: 'xxxx', refreshToken: 'yyyy' }, { accountId: 'qqqq', refreshToken: 'rrrr' }]

I set them like below:

const setRefreshToken = (token, accountId) => {
    let refreshTokensList = JSON.parse(
        JSON.stringify(getCookie(refreshTokens)),
    );

    const item = refreshTokensList.find((rt) => rt.accountId === accountId);

    if (!item) {
        refreshTokensList.push({ accountId, token });
    }
    setCookie(refreshTokens, refreshTokensList, 2);
};
1 Answers

Test this Empty the cookie once, then set the new data But I do not think it works

function del_cookie(refreshTokensList) {
   document.cookie = refreshTokensList + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
I feel the problem is the amount of memory that the cookie takes Because it takes up very little volume, thats 4096 bytes and you cant store, the data cant set on them and you do not receive any errors

My suggestion is use localStorage for multiple refresh tokens If you want, I can explain it to you totally

Related