/*
 * @Description: 
 * @Author: 欧阳承珺
 * @LastEditors: 欧阳承珺
 * @Date: 2022-10-26 09:30:22
 * @LastEditTime: 2022-11-16 15:44:52
 */
import createPersistedState from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'
import { cookieParse } from '~/utils/cookie'


export default ({store, req}) => {
    createPersistedState({
        storage: {
            getItem: (key) => {
                if (process.server) {
                    const parsedCookies = cookieParse(req.headers.cookie)
                    return parsedCookies[key];
                } else {
                    return Cookies.get(key);
                }
            },
            setItem: (key, value) => Cookies.set(key, value, { expires: 15, secure: false }),
            removeItem: key => Cookies.remove(key)
        }
    })(store);

}
