central cookie function

This commit is contained in:
vabene1111
2024-08-21 16:26:13 +02:00
parent 91111c7d74
commit 0eabf1f7c4
2 changed files with 22 additions and 16 deletions

19
vue3/src/utils/cookie.ts Normal file
View File

@@ -0,0 +1,19 @@
/**
* simple function to retrieve a cookie by name
* @param name name of the cookie
*/
export function getCookie(name: string) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}