refreshCookie()

Refreshes a useCookie ref so it reflects the latest browser cookie value.

Since Nuxt 3.10 Spec ↗

Syntax

refreshCookie(name)

Parameters

NameTypeRequiredDescription
name string Yes The cookie name to re-read and sync into its `useCookie` ref.

Returns

void — Updates the matching reactive cookie ref.

Examples

<script setup lang="ts">
const token = useCookie('token')

async function login() {
  await $fetch('/api/login', { method: 'POST' })
  // Server set the cookie via Set-Cookie; sync the client ref
  refreshCookie('token')
}
</script>
<script setup lang="ts">
function syncTheme() {
  refreshCookie('theme')
}
</script>

Notes

Useful when a cookie was changed outside the `useCookie` ref (e.g. an API response set it via `Set-Cookie`, or another tab updated it). It re-reads `document.cookie` and updates the corresponding ref so the UI stays consistent. Client-side utility.

See also