Now I'm using js-cookie to store token in cookie and I meet some problems that I can not get token by Cookies.get method, get method is defined as below:
import Cookies from 'js-cookie'
class CookieService {
get(key: string) {
return Cookies.get(key);
}
set(key: string, value: string, options: object) {
Cookies.set(key, value, options);
}
remove(key: string) {
Cookies.remove(key);
}
}
export default new CookieService();
And using it:
import CookieService from "../../services/CookieService";
...
const token = CookieService.get('accessToken');
console.log(token)
I'm going to show how I set token (response.accessToken is token string), it work correctly:
const options = { path: "/"};
CookieService.set("accessToken", response.accessToken, options);
return true;
And when I use get method, it always return undefined (in nextjs + typescript). But It still shows value of token in console of browser:
Picture link with token on browser console: https://scontent.fsgn5-12.fna.fbcdn.net/v/t1.15752-9/287403467_1031855380665401_1222400127339622022_n.png?_nc_cat=103&ccb=1-7&_nc_sid=ae9488&_nc_ohc=yZwOMW4EQEgAX_34UFy&_nc_ht=scontent.fsgn5-12.fna&oh=03_AVIcjiPBMzy-X8ovKlHd0NtKVh3cYG4_g_VDdIWn1aH8jA&oe=62EACEA2
Please give me some answers for the problem! Many thanks!