No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [SSR] LocalStorage.getItem is not a function

    Help
    2
    2
    1127
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      devlamine last edited by

      Please help,
      I switched to SSR mode for an existing project but had the same error:
      [view-router] uncaught error during route navigation:

      TypeError: quasar__WEBPACK_IMPORTED_MODULE_2 __. LocalStorage.getItem is not a function
      how can I fix that? I used LocalStorage.getItem in several places of my code.
      

      quasar v1

      You can help me please adapt SSR mode in my boot:

      import { LocalStorage } from 'quasar'
      import { onFail } from '../session/logout'
      import appSetup from './app-setup'
      import config from '../config'
      
      var authorized = false
      
      export default () => {
        if (config.localStorage.enableListener) {
          window.addEventListener('storage', (e) => {
            if (!authorized) {
              console.warn('Unauthorized local storage change')
              switch (config.localStorage.unauthChange) {
                case 'block':
                  if (e.key === 'null' || e.key === null) {
                    reload()
                  } else {
                    _LocalStorage.setNative(e.key, e.oldValue)
                  }
                  break
                case 'clear':
                  reload()
                  break
                default:
                  reload()
                  break
              }
            }
          }, false)
        }
        return Promise.resolve(true)
      }
      
      const reload = () => {
        onFail().then(success => appSetup())
      }
      
      export const _LocalStorage = {
        setNative (key, value) {
          authorized = true
          localStorage.setItem(key, value)
          authorized = false
        },
        set (key, value) {
          authorized = true
          LocalStorage.set(key, value)
          authorized = false
        },
        remove (key) {
          authorized = true
          LocalStorage.remove(key)
          authorized = false
        },
        clear () {
          authorized = true
          LocalStorage.clear()
          authorized = false
        },
        get (key) {
          return LocalStorage.getItem(key)
        }
      }
      
      1 Reply Last reply Reply Quote 1
      • M
        matheus.pimentel last edited by

        I having problems whit cookies like so, O know has a division in client side e server side of SSR mode but I don’t found anybody to help…

        1 Reply Last reply Reply Quote 0
        • First post
          Last post