astro-tractstack 2.0.28 → 2.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-tractstack",
3
- "version": "2.0.28",
3
+ "version": "2.0.29",
4
4
  "description": "Astro integration for TractStack - redeeming the web from boring experiences",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -5,22 +5,48 @@ import XMarkIcon from '@heroicons/react/24/solid/XMarkIcon';
5
5
  import { ProfileStorage } from '@/utils/profileStorage';
6
6
  import SandboxRegisterForm from '@/components/codehooks/SandboxRegisterForm';
7
7
 
8
- export default function SandboxAuthWrapper() {
8
+ interface SandboxAuthWrapperProps {
9
+ isServerSideAuthenticated: boolean;
10
+ }
11
+
12
+ export default function SandboxAuthWrapper({
13
+ isServerSideAuthenticated,
14
+ }: SandboxAuthWrapperProps) {
9
15
  const [profileExists, setProfileExists] = useState<boolean | null>(null);
10
16
 
11
17
  useEffect(() => {
12
- setProfileExists(ProfileStorage.hasProfile());
13
- }, []);
18
+ const hasLocalProfile = ProfileStorage.hasProfile();
19
+
20
+ if (hasLocalProfile && !isServerSideAuthenticated) {
21
+ const token = localStorage.getItem('tractstack_profile_token');
22
+
23
+ if (token) {
24
+ ProfileStorage.storeProfileToken(token);
25
+ window.location.reload();
26
+ return;
27
+ } else {
28
+ ProfileStorage.clearProfile();
29
+ setProfileExists(false);
30
+ }
31
+ } else {
32
+ setProfileExists(hasLocalProfile);
33
+ }
34
+ }, [isServerSideAuthenticated]);
14
35
 
15
36
  const handleRegistrationSuccess = () => {
16
37
  setProfileExists(true);
38
+ window.location.reload();
17
39
  };
18
40
 
19
41
  const handleClose = () => {
20
42
  window.location.href = '/';
21
43
  };
22
44
 
23
- if (profileExists === null || profileExists === true) {
45
+ if (profileExists === true && isServerSideAuthenticated) {
46
+ return null;
47
+ }
48
+
49
+ if (profileExists === null) {
24
50
  return null;
25
51
  }
26
52
 
@@ -26,7 +26,6 @@ if (healthCheckRedirect !== undefined) {
26
26
  }
27
27
 
28
28
  const brandConfig = await getBrandConfig(tenantId);
29
-
30
29
  const emptyStoryFragment = {
31
30
  id: ulid(),
32
31
  nodeType: 'StoryFragment' as const,
@@ -43,12 +42,15 @@ const loadData = {
43
42
  };
44
43
  const title = 'Sandbox - TractStack Editor';
45
44
  const storyFragmentID = emptyStoryFragment.id;
46
-
47
45
  const fullContentMap = await getFullContentMap(tenantId);
48
46
  const urlParams: Record<string, string | boolean> = {};
49
47
  for (const [key, value] of Astro.url.searchParams) {
50
48
  urlParams[key] = value === '' ? true : value;
51
49
  }
50
+
51
+ const hasProfile = Astro.request.headers
52
+ .get('cookie')
53
+ ?.includes('tractstack_profile=true');
52
54
  ---
53
55
 
54
56
  <Layout
@@ -59,7 +61,7 @@ for (const [key, value] of Astro.url.searchParams) {
59
61
  isStoryKeep={true}
60
62
  isEditor={true}
61
63
  >
62
- <SandboxAuthWrapper client:load />
64
+ <SandboxAuthWrapper client:load isServerSideAuthenticated={!!hasProfile} />
63
65
  <Header
64
66
  title={title}
65
67
  slug="sandbox"
@@ -70,65 +72,71 @@ for (const [key, value] of Astro.url.searchParams) {
70
72
  menu={null}
71
73
  />
72
74
 
73
- <section
74
- id="storykeepHeader"
75
- role="banner"
76
- class="z-101 bg-mywhite left-0 right-0 drop-shadow transition-all duration-200"
77
- >
78
- <StoryKeepHeader
79
- slug="sandbox"
80
- isContext={false}
81
- isSandboxMode={true}
82
- client:only="react"
83
- />
84
- </section>
85
-
86
- <div class="flex min-h-screen">
87
- <StoryKeepToolMode isContext={false} client:only="react" />
88
-
89
- <main id="mainContent" class="relative flex-1 overflow-x-auto">
90
- <div class="bg-myblue/20 bg-mylightgrey h-full p-1.5">
91
- <div
92
- class="h-fit min-h-screen pb-96"
93
- style={{
94
- backgroundImage:
95
- 'repeating-linear-gradient(135deg, transparent, transparent 10px, rgba(0,0,0,0.05) 10px, rgba(0,0,0,0.05) 20px)',
96
- }}
75
+ {
76
+ hasProfile && (
77
+ <>
78
+ <section
79
+ id="storykeepHeader"
80
+ role="banner"
81
+ class="z-101 bg-mywhite left-0 right-0 drop-shadow transition-all duration-200"
97
82
  >
98
- <Compositor
99
- id={storyFragmentID}
100
- nodes={loadData}
101
- config={brandConfig}
102
- fullContentMap={fullContentMap}
103
- fullCanonicalURL="/sandbox"
104
- urlParams={urlParams}
105
- availableCodeHooks={Object.keys(codeHookComponents)}
83
+ <StoryKeepHeader
84
+ slug="sandbox"
85
+ isContext={false}
106
86
  isSandboxMode={true}
107
87
  client:only="react"
108
88
  />
89
+ </section>
90
+
91
+ <div class="flex min-h-screen">
92
+ <StoryKeepToolMode isContext={false} client:only="react" />
93
+
94
+ <main id="mainContent" class="relative flex-1 overflow-x-auto">
95
+ <div class="bg-myblue/20 bg-mylightgrey h-full p-1.5">
96
+ <div
97
+ class="h-fit min-h-screen pb-96"
98
+ style={{
99
+ backgroundImage:
100
+ 'repeating-linear-gradient(135deg, transparent, transparent 10px, rgba(0,0,0,0.05) 10px, rgba(0,0,0,0.05) 20px)',
101
+ }}
102
+ >
103
+ <Compositor
104
+ id={storyFragmentID}
105
+ nodes={loadData}
106
+ config={brandConfig}
107
+ fullContentMap={fullContentMap}
108
+ fullCanonicalURL="/sandbox"
109
+ urlParams={urlParams}
110
+ availableCodeHooks={Object.keys(codeHookComponents)}
111
+ isSandboxMode={true}
112
+ client:only="react"
113
+ />
114
+ </div>
115
+ </div>
116
+ </main>
109
117
  </div>
110
- </div>
111
- </main>
112
- </div>
113
118
 
114
- <aside
115
- id="settingsControls"
116
- class="z-101 pointer-events-none fixed bottom-16 right-2 flex flex-col items-end gap-2 md:bottom-2"
117
- >
118
- <div class="pointer-events-none flex-grow"></div>
119
+ <aside
120
+ id="settingsControls"
121
+ class="z-101 pointer-events-none fixed bottom-16 right-2 flex flex-col items-end gap-2 md:bottom-2"
122
+ >
123
+ <div class="pointer-events-none flex-grow" />
119
124
 
120
- <div class="pointer-events-auto flex-shrink-0">
121
- <StoryKeepToolBar client:only="react" />
122
- </div>
125
+ <div class="pointer-events-auto flex-shrink-0">
126
+ <StoryKeepToolBar client:only="react" />
127
+ </div>
123
128
 
124
- <div class="pointer-events-auto max-h-full">
125
- <SettingsPanel
126
- config={brandConfig}
127
- availableCodeHooks={Object.keys(codeHookComponents)}
128
- client:only="react"
129
- />
130
- </div>
131
- </aside>
129
+ <div class="pointer-events-auto max-h-full">
130
+ <SettingsPanel
131
+ config={brandConfig}
132
+ availableCodeHooks={Object.keys(codeHookComponents)}
133
+ client:only="react"
134
+ />
135
+ </div>
136
+ </aside>
137
+ </>
138
+ )
139
+ }
132
140
  </Layout>
133
141
 
134
142
  <script>