frontend: fix refreshCookie
This commit is contained in:
@@ -184,13 +184,13 @@ export function formatError(obj) {
|
||||
/**
|
||||
*
|
||||
* @param {string | null} newToken - The new token for the cookie to set
|
||||
* @param {import('@sveltejs/kit').RequestEvent } event - The event object
|
||||
* @param {import('@sveltejs/kit').Cookies } cookies - The event object
|
||||
*/
|
||||
export function refreshCookie(newToken, event) {
|
||||
export function refreshCookie(newToken, cookies) {
|
||||
if (newToken) {
|
||||
const match = newToken.match(/jwt=([^;]+)/);
|
||||
if (match) {
|
||||
event.cookies.set('jwt', match[1], {
|
||||
cookies.set('jwt', match[1], {
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // Secure in production
|
||||
@@ -200,36 +200,3 @@ export function refreshCookie(newToken, event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a debounced version of an input event handler.
|
||||
*
|
||||
* @param {HTMLElement} element - The HTML element to attach the debounced event to.
|
||||
* @param {number} duration - The delay in milliseconds before the event is triggered after the last input.
|
||||
* @returns {Object} - An object with a `destroy` method to clean up the event listener.
|
||||
*
|
||||
* @example
|
||||
* <input use:debounce={300} on:debouncedinput={handleInput} />
|
||||
*/
|
||||
export function debounce(element, duration) {
|
||||
/** @type{NodeJS.Timeout} */
|
||||
let timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {CustomEventInit} e
|
||||
*/
|
||||
function input(e) {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
element.dispatchEvent(new CustomEvent('debouncedinput', e));
|
||||
}, duration);
|
||||
}
|
||||
|
||||
element.addEventListener('input', input);
|
||||
return {
|
||||
destroy() {
|
||||
element.removeEventListener('input', input);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user