Skip to content

Commit

Permalink
fix: update README to include module type for script and enhance toke…
Browse files Browse the repository at this point in the history
…n handling in test.js
  • Loading branch information
fatin-webEfo committed Jan 23, 2025
1 parent acc18e9 commit 82b2b45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Copy and paste the following script into your Squarespace Code Injection section

```html
<script id="squarecraft-script"
type="module"
src="https://fatin-webefo.github.io/squarespace-block/scripts/test.js" defer>
</script>

Expand Down
11 changes: 8 additions & 3 deletions src/plugins/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import axios from "axios";

document.addEventListener("DOMContentLoaded", function () {
console.log("✅ SquareCraft Plugin Loaded");

const token = localStorage.getItem('token') || document.cookie.match(/(?:^|;\s*)token=([^;]*)/)[1];
console.log(token);
let selectedElement = null;

// Create & Inject Widget Button
Expand Down Expand Up @@ -85,7 +86,9 @@ document.addEventListener("DOMContentLoaded", function () {
fontSize: fontSize,
},
}, {
withCredentials: true, // Ensures cookies and credentials are included
headers: {
Authorization: `Bearer ${token}`,
} // Ensures cookies and credentials are included
})
.then(response => console.log("Styles saved to backend:", response.data))
.catch(error => console.error("Error saving styles:", error));
Expand All @@ -94,7 +97,9 @@ document.addEventListener("DOMContentLoaded", function () {

// Load saved styles from backend API using Axios
axios.get("http://localhost:8000/api/v1/modifications", {
withCredentials: true, // Ensures cookies and credentials are included
headers: {
Authorization: `Bearer ${token}`,
} // Ensures cookies and credentials are included
})
.then(response => {
const styles = response.data;
Expand Down

0 comments on commit 82b2b45

Please sign in to comment.