Fix CSRF token undefined error in user_tokens.html template

- Remove undefined csrf_token() function calls from JavaScript code
- The API token management routes use session-based authentication (Flask-Login)
- CSRF protection was not properly configured in the Flask application
- Template now loads without Jinja2 template errors
parent f4ca50d6
...@@ -260,8 +260,7 @@ document.getElementById('createTokenForm').addEventListener('submit', async func ...@@ -260,8 +260,7 @@ document.getElementById('createTokenForm').addEventListener('submit', async func
const response = await fetch('{{ url_for("main.create_api_token") }}', { const response = await fetch('{{ url_for("main.create_api_token") }}', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json'
'X-CSRFToken': '{{ csrf_token() }}'
}, },
body: JSON.stringify({ name: tokenName }) body: JSON.stringify({ name: tokenName })
}); });
...@@ -308,8 +307,7 @@ document.getElementById('extendTokenForm').addEventListener('submit', async func ...@@ -308,8 +307,7 @@ document.getElementById('extendTokenForm').addEventListener('submit', async func
const response = await fetch(`{{ url_for("main.extend_api_token", token_id=0) }}`.replace('0', currentTokenId), { const response = await fetch(`{{ url_for("main.extend_api_token", token_id=0) }}`.replace('0', currentTokenId), {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json'
'X-CSRFToken': '{{ csrf_token() }}'
}, },
body: JSON.stringify({ days: days }) body: JSON.stringify({ days: days })
}); });
...@@ -338,10 +336,7 @@ async function revokeToken(tokenId, tokenName) { ...@@ -338,10 +336,7 @@ async function revokeToken(tokenId, tokenName) {
try { try {
const response = await fetch(`{{ url_for("main.revoke_api_token", token_id=0) }}`.replace('0', tokenId), { const response = await fetch(`{{ url_for("main.revoke_api_token", token_id=0) }}`.replace('0', tokenId), {
method: 'POST', method: 'POST'
headers: {
'X-CSRFToken': '{{ csrf_token() }}'
}
}); });
const data = await response.json(); const data = await response.json();
...@@ -365,10 +360,7 @@ async function deleteToken(tokenId, tokenName) { ...@@ -365,10 +360,7 @@ async function deleteToken(tokenId, tokenName) {
try { try {
const response = await fetch(`{{ url_for("main.delete_api_token", token_id=0) }}`.replace('0', tokenId), { const response = await fetch(`{{ url_for("main.delete_api_token", token_id=0) }}`.replace('0', tokenId), {
method: 'DELETE', method: 'DELETE'
headers: {
'X-CSRFToken': '{{ csrf_token() }}'
}
}); });
const data = await response.json(); const data = await response.json();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment