-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add refresh option to useCookie() to extend cookie expiration #33811
Copy link
Copy link
Closed
Labels
Description
Describe the feature
Add a refresh option to the useCookie composable to allow extending the cookie expiration
even when the value remains unchanged. This is useful for cookies that should stay alive
as long as the user is active, without changing the value.
Current behavior
When updating a cookie with the same value, its expiration time does not reset.
Expected behavior
With a new option refresh: true, setting the cookie even to the same value
should update the expiration time according to maxAge.
Example
<script setup lang="ts">
const testCookie = useCookie('test-cookie', {
maxAge: 60 * 60,
default: () => 'defaultValue',
refresh: true,
})
if (import.meta.server) {
testCookie.value = 'defaultValue' // cookie expiration should be extended
}
const changeCookie = () => {
testCookie.value = 'defaultValue' // cookie expiration should be extended
}
</script>
<template>
<div>
testCookie: {{ testCookie }}
<button @click="changeCookie">
change cookie
</button>
</div>
</template>Additional information
- Would you be willing to help implement this feature?
- Could this feature be implemented as a module?
Final checks
- Read the contribution guide.
- Check existing discussions and issues.
Reactions are currently unavailable