Skip to main content

useSecureStorage
hook

The useSecureStorage hook provides functions to interact with secure storage. It allows you to store, retrieve, and manage sensitive data that requires encryption and secure handling. You can currently only set one secret per Mini.

Anchor to useSecureStorage
useSecureStorage()

UseSecureStorageReturns

getSecret
() => Promise<string>

Get the secret from the secure storage.

removeSecret
() => Promise<void>

Remove the secret from the secure storage.

setSecret
(params: ) => Promise<void>

Set a secret in the secure storage.

Was this section helpful?

Example code

import {useEffect} from 'react'

import {useSecureStorage} from '@shopify/shop-minis-react'

export default function MyComponent() {
const {getSecret, setSecret, removeSecret} = useSecureStorage()

useEffect(() => {
async function handleSecureStorageOperations() {
// Get a secret from secure storage
const secret = await getSecret()
console.log({secret})

// Set a secret in secure storage
await setSecret({value: 'Sensitive Data'})

// Remove a secret from secure storage
await removeSecret()
}

handleSecureStorageOperations()
}, [getSecret, setSecret, removeSecret])
}