-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4d018d
commit 50fe46e
Showing
2 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
import { $fetch } from 'ofetch' | ||
|
||
export default defineEventHandler(async (event) => { | ||
const config = useRuntimeConfig() | ||
console.log('Server config:', config) // For debugging | ||
|
||
const craftUrl = config.CRAFT_URL | ||
|
||
if (!craftUrl) { | ||
console.error('CRAFT_URL is not defined in server environment') // Add this line for debugging | ||
console.error('CRAFT_URL is not defined in server environment') | ||
throw createError({ | ||
statusCode: 500, | ||
statusMessage: 'CRAFT_URL is not defined in server environment', | ||
}) | ||
} | ||
|
||
try { | ||
console.log('Fetching from:', `${craftUrl}/actions/users/session-info`) // Add this line for debugging | ||
const response = await fetch(`${craftUrl}/actions/users/session-info`, { | ||
const url = `${craftUrl}/actions/users/session-info` | ||
console.log('Fetching from:', url) // For debugging | ||
|
||
const data = await $fetch(url, { | ||
headers: { | ||
'Accept': 'application/json', | ||
}, | ||
}) | ||
const data = await response.json() | ||
|
||
console.log('Response data:', data) // For debugging | ||
|
||
return { csrfToken: data.csrfTokenValue } | ||
} catch (error) { | ||
console.error('Error fetching CSRF token:', error) | ||
throw createError({ | ||
statusCode: 500, | ||
statusMessage: 'Failed to fetch CSRF token', | ||
statusMessage: 'Failed to fetch CSRF token: ' + error.message, | ||
}) | ||
} | ||
}) |