Home > Software engineering >  Is it possible to call local storage in SSR Nuxt application middleware?
Is it possible to call local storage in SSR Nuxt application middleware?

Time:10-22

I have a Nuxt app with this middleware

middleware(context) {
    const token = context.route.query.token;

    if (!token) {
        const result = await context.$api.campaignNewShare.createNewShare();
        context.redirect({'name': 'campaigns-new', 'query': {token: result.data.token}});
        local.storage.setKey(token, new DateTime().getTime());
    }
},

I need to store the token to the local storage but I am not sure if it is possible or safe.

CodePudding user response:

No, that is impossible. localStorage is a browser part, but on SSR the code evaluates on the server-side. Using cookies is a good solution.

I recommend to use this module: https://github.com/nuxt-community/universal-storage-module

  • Related