
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
nuxt3-pinia
Advanced tools
Nuxt3 module with autoimport and secure persist(localstorage, sessionstoage, cookie), expire option for pinia
A nuxt3 module that helps you easily and powerfully use the Pinia state repository. Provides state value preservation through web storage(localstorage, sessionstorage), and additional options for specifying expiration times and versions of state values for better utilization.
Easy to use!
** Use Case Screenshot
** Example of Persistent State Values through WebStorage
한국어 링크: https://github.com/rubystarashe/nuxt3-pinia/blob/master/README-kor.md
https://github.com/rubystarashe/nuxt3-pinia-playground
npm i nuxt3-pinia
// nuxt.config.js
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: ['nuxt3-pinia']
})
// store/index.js
export const store1 = {
state: () => {
return {
foo: 'bar'
}
}
}
export const store2 = () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
}
// app.vue
<script setup>
const { foo } = getStoreRefs('store1')
const store2 = getStore('store2')
const { count, doubleCount } = store2.toRefs()
const { increment } = store2
</script>
// If you set the store module to store/index.js as follows:
export default {
state: () => {
return {
count: 0
}
}
}
// default can be called as getStore('default')
export const test = {
state: () => {
return {
foo: 'bar'
}
}
}
// test can be called as getStore('test')
// If you set the store module to store/othername.js as follows:
export default {
state: () => {
return {
count: 0
}
}
}
// default is omitted name and can be called as getStore('othername')
export const nextname = {
state: () => {
return {
foo: 'bar'
}
}
}
// nextname can be called as getStore('othername/nextname')
// If you set the store module to store/depth1/depth2.js as follows:
export default {
state: () => {
return {
count: 0
}
}
}
// default is omitted name and can be called as getStore('depth1/depth2')
export const depth3 = {
state: () => {
return {
foo: 'bar'
}
}
}
// depth3 can be called as getStore('depth1/depth2/depth3')
You can specify the name of the directory path from which you want to read the store modules
// nuxt.config.js
import { defineNuxtConfig } from "nuxt"
export default defineNuxtConfig({
modules: ['nuxt3-pinia'],
pinia: {
autoImport: 'store' // Default value is 'store'. If it is false, it does not read automatically any folder
}
})
// get store api
const store1 = getStore('store1')
const store2 = store('store2')
// Gets the states of the store as reactive objects
const store1_refs = store1.toRefs()
const store2_refs = storeToRefs(store2)
const store3_refs = getStoreRefs('store3')
const store4_refs = storeRefs('store4')
In addition to creating module files in the specified folder, you can create stores within the vue instance
const newStore = defineStore('storename', {
state: () => {
return {
foo: 'bar'
}
}
})
// defineStore creates a store object and registers the created store globally
// Therefore, it can be retrieved from other components through get store api without additional settings
const store_by_get = getStore('storename')
You can access the Nuxt app to get global pinia instance. You can also refer to the list of stores registered as modules by referring to pinia.stores or $pinia
const { pinia, $pinia } = useNuxtApp()
const stores = pinia.stores // === $pinia
const store1 = $pinia['store1']()
const store2 = pinia.stores['store1']()
When you create a store, you can specify that the status is stored in web storage by granting the persist option
export default {
persist: 'localStorage' // local, localStorage, session, sessionStorage.
state: () => {
return {
foo: 'bar'
}
}
}
Stores with persist option can see persist point in time through the $persist property of the store
<template>
<div v-if="store.$setup.$persist">
{{store.foo}}
</div>
</template>
<script setup>
const store = getStore('default')
</script>
Or you can use isStoreLoaded function instead of $persist to match the hydration time
<template>
<div v-if="isLoaded">
{{store.foo}}
</div>
</template>
<script setup>
const store = getStore('default')
const isLoaded = isStoreLoaded()
</script>
When you create a store, you can set how long the state is stored on the web storage by granting the expire option
export default {
persist: true, // === localStorage
expire: 1000 * 60 * 60 // expire or expirein key. ms.
state: () => {
return {
foo: 'bar'
}
}
}
If the version of the saved state changes, the default value of the new version is saved to web storage without recalling the store state that was previously saved
export default {
persist: true,
version: 'some version', // any
state: () => {
return {
foo: 'bar'
}
}
}
FAQs
Nuxt3 module with autoimport and secure persist(localstorage, sessionstoage, cookie), expire option for pinia
The npm package nuxt3-pinia receives a total of 5 weekly downloads. As such, nuxt3-pinia popularity was classified as not popular.
We found that nuxt3-pinia demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.