Skip to content

Commit

Permalink
Support new Daisy UI template along with CRUD operations
Browse files Browse the repository at this point in the history
  • Loading branch information
thobson committed Sep 2, 2024
1 parent 5261d1d commit 3297882
Show file tree
Hide file tree
Showing 264 changed files with 2,925 additions and 3,347 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "public",
"description": "Monorepo containing the JS/TS client libraries",
"version": "0.9.23",
"version": "0.9.24",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ in README.template.md and outputs to README.md
<br />
<a href="#{GITHUB_REPO}#">GitHub</a>
·
<a href="#{DEMO_SITE}#">Demo</a>
<a href="#{PRELINE_DEMO_SITE}#">Demo</a>
·
<a href="#{DOCS}#">Documentation</a>
·
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@passlock/client",
"version": "0.9.23",
"version": "0.9.24",
"description": "Passkey authentication and social login for web apps (Typescript). Framework agnostic",
"keywords": [
"passkey",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-sveltekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ in README.template.md and outputs to README.md
☝️ Google sign in / one-tap
📪 Mailbox verification (via a one time code or link)
🌘 Dark mode with theme selection (light/dark/system)
🚀 [Preline][preline] and [Shadcn][shadcn] variants
🚀 [Daisy UI][daisy], [Preline][preline] and [Shadcn][shadcn] variants

## Requirements

Expand Down Expand Up @@ -82,5 +82,6 @@ Please see the template [homepage][homepage]
[passlock-apikeys]: https://console.passlock.dev/apikeys
[pnpm]: https://pnpm.io/installation
[preline]: https://preline.co
[daisy]: https://daisyui.com
[shadcn]: https://www.shadcn-svelte.com
[homepage]: https://github.com/passlock-dev/ts-clients/packages/create-sveltekit/docs/README.md
5 changes: 3 additions & 2 deletions packages/create-sveltekit/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in README.template.md and outputs to README.md
<br />
<a href="#{GITHUB_REPO}#">GitHub</a>
·
<a href="#{DEMO_SITE}#">Demo</a>
<a href="#{PRELINE_DEMO_SITE}#">Demo</a>
·
<a href="#{DOCS}#">Documentation</a>
·
Expand All @@ -34,7 +34,7 @@ in README.template.md and outputs to README.md
☝️ Google sign in / one-tap
📪 Mailbox verification (via a one time code or link)
🌘 Dark mode with theme selection (light/dark/system)
🚀 [Preline][preline] and [Shadcn][shadcn] variants
🚀 [Daisy UI][daisy], [Preline][preline] and [Shadcn][shadcn] variants

## Requirements

Expand Down Expand Up @@ -82,5 +82,6 @@ Please see the template [homepage][homepage]
[passlock-apikeys]: https://console.passlock.dev/apikeys
[pnpm]: https://pnpm.io/installation
[preline]: https://preline.co
[daisy]: https://daisyui.com
[shadcn]: https://www.shadcn-svelte.com
[homepage]: https://github.com/passlock-dev/ts-clients/packages/create-sveltekit/docs/README.md
5 changes: 3 additions & 2 deletions packages/create-sveltekit/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ in README.template.md and outputs to README.md
<p align="center">
Sveltekit starter template featuring Passkeys, Social Login (Apple & Google) and more...
<br />
<a href="https://d1rl0ue18b0151.cloudfront.net">Demo (Preline)</a> &nbsp; | &nbsp; <a href="https://dbr4qrmypnl85.cloudfront.net">Demo (Shadcn)</a>
<a href="https://d1p6mpdsb02lid.cloudfront.net">Demo (Daisy UI)</a> &nbsp; | &nbsp; <a href="https://d1rl0ue18b0151.cloudfront.net">Demo (Preline)</a> | &nbsp; <a href="https://dbr4qrmypnl85.cloudfront.net">Demo (Shadcn)</a>
</p>

## Features
Expand All @@ -30,7 +30,7 @@ in README.template.md and outputs to README.md
☝️ Google sign in / one-tap
📪 Mailbox verification (via a one time code or link)
🌘 Dark mode with theme selection (light/dark/system)
🚀 [Preline][preline] and [Shadcn][shadcn] variants
🚀 [Daisy UI][daisy], [Preline][preline] and [Shadcn][shadcn] variants

## Screenshots

Expand Down Expand Up @@ -222,6 +222,7 @@ Please file an [issue][issues] and I'll respond ASAP.
[lucia]: https://lucia-auth.com
[tailwind]: https://tailwindcss.com
[preline]: https://preline.co
[daisy]: https://daisyui.com
[meltui]: https://melt-ui.com
[shadcn]: https://www.shadcn-svelte.com
[passlock-signup]: https://console.passlock.dev/register
Expand Down
5 changes: 3 additions & 2 deletions packages/create-sveltekit/docs/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ in README.template.md and outputs to README.md
<p align="center">
Sveltekit starter template featuring Passkeys, Social Login (Apple & Google) and more...
<br />
<a href="#{DEMO_SITE}#">Demo (Preline)</a> &nbsp; | &nbsp; <a href="#{SHADCN_DEMO_SITE}#">Demo (Shadcn)</a>
<a href="#{DAISY_DEMO_SITE}#">Demo (Daisy UI)</a> &nbsp; | &nbsp; <a href="#{PRELINE_DEMO_SITE}#">Demo (Preline)</a> | &nbsp; <a href="#{SHADCN_DEMO_SITE}#">Demo (Shadcn)</a>
</p>

## Features
Expand All @@ -30,7 +30,7 @@ in README.template.md and outputs to README.md
☝️ Google sign in / one-tap
📪 Mailbox verification (via a one time code or link)
🌘 Dark mode with theme selection (light/dark/system)
🚀 [Preline][preline] and [Shadcn][shadcn] variants
🚀 [Daisy UI][daisy], [Preline][preline] and [Shadcn][shadcn] variants

## Screenshots

Expand Down Expand Up @@ -222,6 +222,7 @@ Please file an [issue][issues] and I'll respond ASAP.
[lucia]: https://lucia-auth.com
[tailwind]: https://tailwindcss.com
[preline]: https://preline.co
[daisy]: https://daisyui.com
[meltui]: https://melt-ui.com
[shadcn]: https://www.shadcn-svelte.com
[passlock-signup]: https://console.passlock.dev/register
Expand Down
2 changes: 1 addition & 1 deletion packages/create-sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@passlock/create-sveltekit",
"version": "0.9.22",
"version": "0.9.24",
"description": "A CLI for creating new SvelteKit projects with Passkey authentication, Social Login and more",
"keywords": [
"create",
Expand Down
36 changes: 33 additions & 3 deletions packages/create-sveltekit/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ async function main() {
{
value: 'preline',
label: 'Preline CSS',
hint: 'Lucia, Preline & Superforms',
hint: 'Prisma, Lucia, Preline & Superforms',
},
{
value: 'daisy',
label: 'Daisy UI',
hint: 'Prisma, Lucia, Daisy UI & Superforms',
},
{
value: 'shadcn',
label: 'Shadcn/ui',
hint: 'Lucia, Shadcn/ui (Svelte fork) & Superforms',
hint: 'Prisma, Lucia, Shadcn/ui (Svelte fork) & Superforms',
},
],
initialValue: 'preline',
Expand Down Expand Up @@ -110,7 +115,6 @@ async function main() {

if (dependencies) {
const s = spinner()

s.start('Installing dependencies...')

try {
Expand All @@ -125,6 +129,32 @@ async function main() {
s.stop('Installed dependencies.')
}

// ask to setup prisma
const prisma = await confirm({
message: 'Setup Sqlite dev database? (requires pnpm)',
})

if (isCancel(prisma)) {
cancel('Operation cancelled.')
return process.exit(0)
}

if (prisma) {
const s = spinner()
s.start('Creating Sqlite database...')

try {
await execSync('pnpm run prisma:migrate', { cwd })
} catch {
console.log()
console.log('📦️ pnpm is required:')
console.log('npm i -g pnpm')
return process.exit(0)
}

s.stop('Database created.')
}

note(outroNote, 'Important')

outro('Done. 👌')
Expand Down
11 changes: 10 additions & 1 deletion packages/create-sveltekit/templates/common/.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ PUBLIC_APPLE_CLIENT_ID = ''
# however Apple still requires us to pass a redirect url
# during authentication, and it must match one of the Website URLs
# the Service ID was configured with
PUBLIC_APPLE_REDIRECT_URL = ''
PUBLIC_APPLE_REDIRECT_URL = ''

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="file:./dev.db"
7 changes: 6 additions & 1 deletion packages/create-sveltekit/templates/common/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Passlock also handles social sign in, abstracting passkey and google authenticat

During registration and authentication, Passlock returns a token. We send this token to the backend actions and verify it's authenticity via the Passlock REST API.

## Prisma

[Primsa][prisma] is a SQL ORM that works well with both Typescript and Prisma. Lucia (see below) has built in support for Prisma.

## Lucia

[Lucia][lucia] handles sessions. Put simply, when a user authenticates, Passlock returns a token. A backend `+page.server.ts` action verifies the token is authentic, then creates a Lucia session. Lucia supports many database backends, this example uses sqlite.
Expand Down Expand Up @@ -83,7 +87,7 @@ Similar conceptually, the heaby lifting is offloaded to Passlock. We just need t

## Hooks

We want to protect the `/app` route. We do this in [src/hooks.server.ts](../src/hooks.server.ts) by checking the route id and user/session status.
We want to protect the `/todos` route. We do this in [src/hooks.server.ts](../src/hooks.server.ts) by checking the route id and user/session status.

## Mailbox verification

Expand Down Expand Up @@ -121,6 +125,7 @@ Passlock will send the user to this route, appending a `?code=xxx` query paramet
> Why do it this way? Why not simply verify the code in the +page.server.ts load function? Because we may need to re-authenticate the user. For background please see the [passlock docs](https://docs.passlock.dev/docs/howto/verify-emails#re-authenticating-the-user)
[passlock]: https://passlock.dev
[prisma]: https://www.prisma.io/orm
[lucia]: https://lucia-auth.com
[tailwind]: https://tailwindcss.com
[preline]: https://preline.co
Expand Down
12 changes: 7 additions & 5 deletions packages/create-sveltekit/templates/common/ignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
build
.svelte-kit
package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
sqlite.db
TODO.txt

# sst
.sst
sst.config.ts
src/sst-env.d.ts
src/sst-env.d.ts

# prisma
prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL PRIMARY KEY,
"email" TEXT NOT NULL,
"givenName" TEXT NOT NULL,
"familyName" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"expiresAt" DATETIME NOT NULL,
CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Todo" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"text" TEXT NOT NULL,
CONSTRAINT "Todo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
37 changes: 37 additions & 0 deletions packages/create-sveltekit/templates/common/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model User {
id String @id
email String @unique
givenName String
familyName String
sessions Session[]
todos Todo[]
}

model Session {
id String @id
userId String
expiresAt DateTime
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
}

model Todo {
id String @id
userId String
text String
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
}
3 changes: 1 addition & 2 deletions packages/create-sveltekit/templates/common/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ declare global {
const google: typeof import('google-one-tap')
}

export { }

export {}
14 changes: 6 additions & 8 deletions packages/create-sveltekit/templates/common/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { login } from '$lib/routes'
import { lucia } from '$lib/server/auth'
import { initLucia } from '$lib/server/db'
import { redirect, type Handle } from '@sveltejs/kit'

// protect /todos
const isProtectedRoute = (routeId: string | null) => routeId?.startsWith('/(app)')

export const handle: Handle = async ({ event, resolve }) => {
const sessionId = event.cookies.get(lucia.sessionCookieName)

if (!sessionId && isProtectedRoute(event.route.id)) {
return redirect(302, '/')
return redirect(302, '/login')
} else if (!sessionId) {
event.locals.user = null
event.locals.session = null
Expand All @@ -19,25 +19,25 @@ export const handle: Handle = async ({ event, resolve }) => {
const { session, user } = await lucia.validateSession(sessionId)

if (session && session.fresh) {
// update the cookie with the new session id
const sessionCookie = lucia.createSessionCookie(session.id)
// sveltekit types deviates from the de-facto standard
// you can use 'as any' too
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: '/',
...sessionCookie.attributes
})
}

if (!session) {
// session id was invalid so set a blank cookie
const sessionCookie = lucia.createBlankSessionCookie()
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: '/',
...sessionCookie.attributes
})
}

event.locals.user = user || null
event.locals.session = session || null
event.locals.user = user
event.locals.session = session

if (isProtectedRoute(event.route.id) && event.locals.user) {
return resolve(event)
Expand All @@ -47,5 +47,3 @@ export const handle: Handle = async ({ event, resolve }) => {
return resolve(event)
}
}

initLucia()
Loading

0 comments on commit 3297882

Please sign in to comment.