-
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
Showing
14 changed files
with
182 additions
and
61 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
backend/config/project/graphql/schemas/c7d2eb61-cdde-4a76-88a9-eb30ddcf155b.yaml
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,4 +1,4 @@ | ||
dateModified: 1727771251 | ||
dateModified: 1727924935 | ||
elementSources: | ||
craft\elements\Entry: | ||
- | ||
|
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,9 +1,84 @@ | ||
<script setup> | ||
import { ref } from 'vue' | ||
import { useLazyAsyncData, useRuntimeConfig } from '#imports' | ||
const config = useRuntimeConfig() | ||
const message = ref('') | ||
const title = ref('Post ') | ||
const loading = ref(false) | ||
const fetchCsrfToken = async () => { | ||
try { | ||
const response = await fetch('/api/csrf') | ||
const data = await response.json() | ||
return data.csrfToken | ||
console('CSRF acquired ' + data.csrfToken) | ||
} catch (error) { | ||
console.error('Error fetching CSRF token:', error) | ||
return null | ||
} | ||
} | ||
const { data: csrfTokenData, error: csrfError } = await useFetch('/api/csrf') | ||
const csrfToken = ref(csrfTokenData.value?.csrfToken) | ||
if (csrfError.value) { | ||
console.error('Error fetching CSRF token:', csrfError.value) | ||
} | ||
const submitPost = async () => { | ||
if (!csrfToken.value) { | ||
console.error('CSRF token not available') | ||
return | ||
} | ||
loading.value = true | ||
try { | ||
console.log('Submitting post with title:', title.value, 'and message:', message.value) | ||
console.log('CSRF Token:', csrfToken.value) | ||
const result = await GqlCreatePost({ | ||
title: title.value, | ||
message: message.value | ||
}, { | ||
headers: { | ||
'X-CSRF-Token': csrfToken.value, | ||
} | ||
}) | ||
console.log('Raw response:', result) | ||
if (result.error) { | ||
console.error('GraphQL Error:', result.error) | ||
throw new Error(JSON.stringify(result.error)) | ||
} | ||
if (!result.data) { | ||
throw new Error('No data returned from the mutation') | ||
} | ||
console.log('Post created:', result.data) | ||
// Clear the form fields after successful submission | ||
title.value = 'Post ' | ||
message.value = '' | ||
} catch (err) { | ||
console.error('Error creating post:', err) | ||
if (err.response) { | ||
console.error('Response status:', err.response.status) | ||
console.error('Response data:', await err.response.text()) | ||
} | ||
} finally { | ||
loading.value = false | ||
} | ||
} | ||
</script> | ||
<template> | ||
<form method="post"> | ||
<form method="post" @submit.prevent="submitPost"> | ||
<div class="mb-6 mt-4"> | ||
<label for="post" class="font-bold">Message</label> | ||
<textarea name="fields[textBlock]" class="w-full px-6 py-4" required id="message"></textarea> | ||
<label for="message" class="font-bold">Message</label> | ||
<textarea name="message" class="w-full px-6 py-4" required id="message" v-model="message"></textarea> | ||
</div> | ||
<input type="submit" class="rounded font-bold bg-red-600 text-slate-50 px-6 py-4" value="Post entry" /> | ||
</form> | ||
<input type="submit" class="rounded font-bold bg-red-600 text-slate-50 px-6 py-4" value="Post entry" :disabled="loading"> | ||
</form> | ||
</template> |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -18,3 +18,4 @@ query Guestbook($limit: Int!, $offset: Int!) { | |
} | ||
entryCount(section: "posts") | ||
} | ||
|
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mutation createPost($title: String!, $message: String) { | ||
save_posts_text_Entry( | ||
title: $title, | ||
textBlock: $message, | ||
authorId: 1 | ||
) { | ||
title | ||
textBlock | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type Mutation { | ||
save_posts_text_Entry(title: String!, textBlock: String): Entry | ||
} | ||
|
||
type Entry { | ||
id: ID | ||
title: String | ||
textBlock: String | ||
} | ||
|
||
type Query { | ||
entries: [Entry] | ||
} |
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 |
---|---|---|
@@ -0,0 +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') | ||
throw createError({ | ||
statusCode: 500, | ||
statusMessage: 'CRAFT_URL is not defined in server environment', | ||
}) | ||
} | ||
|
||
try { | ||
const url = `${craftUrl}/actions/users/session-info` | ||
console.log('Fetching from:', url) // For debugging | ||
|
||
const data = await $fetch(url, { | ||
headers: { | ||
'Accept': 'application/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: ' + error.message, | ||
}) | ||
} | ||
}) |