create-mikstack 0.1.11 → 0.1.13

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": "create-mikstack",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,4 @@
1
- import type { Handle } from "@sveltejs/kit";
1
+ import { redirect, type Handle } from "@sveltejs/kit";
2
2
  import { auth } from "$lib/server/auth";
3
3
  import { svelteKitHandler } from "better-auth/svelte-kit";
4
4
  import { building } from "$app/environment";
@@ -11,5 +11,9 @@ export const handle: Handle = async ({ event, resolve }) => {
11
11
  event.locals.user = session?.user ?? null;
12
12
  event.locals.session = session?.session ?? null;
13
13
 
14
+ if (event.route.id?.startsWith("/(app)") && !event.locals.user) {
15
+ redirect(302, "/sign-in");
16
+ }
17
+
14
18
  return svelteKitHandler({ event, resolve, auth, building });
15
19
  };
@@ -1,4 +1,4 @@
1
- import { html, body, section, text, button, link, divider, render } from "@mikstack/email";
1
+ import { html, body, section, text, button, render } from "@mikstack/email";
2
2
 
3
3
  export function magicLinkEmail(url: string) {
4
4
  const email = html(
@@ -13,11 +13,14 @@ export function magicLinkEmail(url: string) {
13
13
  marginBottom: 40,
14
14
  marginTop: 40,
15
15
  }),
16
- link("Click here to sign in with this magic link", {
16
+ button("Sign in", {
17
17
  href: url,
18
- color: "#2563eb",
18
+ backgroundColor: "#111827",
19
+ color: "#ffffff",
19
20
  fontSize: 14,
20
- textDecoration: "underline",
21
+ fontWeight: "bold",
22
+ padding: [12, 34],
23
+ borderRadius: 6,
21
24
  marginBottom: 16,
22
25
  }),
23
26
  text("Or, copy and paste this temporary login URL:", {
@@ -1,5 +1,5 @@
1
1
  import type { LayoutServerLoad } from "./$types";
2
2
 
3
3
  export const load: LayoutServerLoad = ({ locals }) => {
4
- return { user: locals.user };
4
+ return { user: locals.user! };
5
5
  };
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { LayoutData } from "./$types";
4
+ import { Z } from "zero-svelte";
5
+ import { PUBLIC_SERVER } from "$env/static/public";
6
+ import { schema } from "$lib/zero/schema";
7
+ import { mutators } from "$lib/zero/mutators";
8
+ import { set_z } from "$lib/z.svelte";
9
+
10
+ let { data, children }: { data: LayoutData; children: Snippet } = $props();
11
+
12
+ set_z(
13
+ new Z({
14
+ get userID() {
15
+ return data.user.id;
16
+ },
17
+ server: PUBLIC_SERVER,
18
+ schema,
19
+ mutators,
20
+ kvStore: "idb",
21
+ context: {
22
+ get userID() {
23
+ return data.user.id;
24
+ },
25
+ },
26
+ }),
27
+ );
28
+ </script>
29
+
30
+ {@render children()}
@@ -23,8 +23,8 @@ export const GET: RequestHandler = async ({ params }) => {
23
23
 
24
24
  const wrapper = `<!DOCTYPE html>
25
25
  <html>
26
- <head><meta charset="utf-8">${title}<style>*{margin:0;padding:0}html,body{height:100%;background:#e5e7eb}iframe{display:block;max-width:600px;width:100%;height:100%;margin:0 auto;border:none;background:#fff}</style></head>
27
- <body><iframe srcdoc="${escaped}"></iframe></body>
26
+ <head><meta charset="utf-8">${title}<style>*{margin:0;padding:0}html,body{background:#e5e7eb}iframe{display:block;max-width:600px;width:100%;margin:24px auto;border:none;background:#fff}</style></head>
27
+ <body><iframe srcdoc="${escaped}" onload="this.style.height=this.contentDocument.documentElement.scrollHeight+'px'"></iframe></body>
28
28
  </html>`;
29
29
 
30
30
  return new Response(wrapper, {
@@ -1,7 +0,0 @@
1
- import { redirect } from "@sveltejs/kit";
2
- import type { PageServerLoad } from "./$types";
3
-
4
- export const load: PageServerLoad = ({ locals }) => {
5
- if (!locals.user) redirect(302, "/sign-in");
6
- return { user: locals.user };
7
- };