[Vuejs]-Access Vuex store from javascript module

0👍

Answering your first question, when you want to use the store from outside Vue just use its API as you are doing though you don’t really need to check for the store or the state to be initialized.

Regarding security, storing the authorization token in JS will be vulnerable to XSS attacks, the best way to avoid (or mitigate) them is implementing a robust Content Security Policy (CSP) and using a low (5-10min) time to live for your tokens.

On a side note, you don’t need to rename store to cstore and if you use class methods instead of adding function properties in the constructor you wont need to juggle with this. Also note that storing the token in memory will not survive a page refresh so you may want to store it in sessionStorage.

Leave a comment