Skip to content

Commit

Permalink
Merge pull request #2140 from undb-io/release/v1.0.0-119
Browse files Browse the repository at this point in the history
Release version v1.0.0-119
  • Loading branch information
nichenqin authored Nov 13, 2024
2 parents 1f07529 + b6556f0 commit 5a3b9ad
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 78 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.0.0-119


### 🩹 Fixes

- Fix update record form validation ([c695ffe](https://github.com/undb-io/undb/commit/c695ffe))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v1.0.0-118


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY . .

RUN bun install

EXPOSE 5173
EXPOSE 3721

ENTRYPOINT ["/tini", "--"]
CMD ["bun", "run", "dev"]
4 changes: 2 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"build:docker": "bun build --compile src/index.ts --target=bun --packages=external --sourcemap --outfile undb"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.686.0",
"@aws-sdk/s3-request-presigner": "^3.686.0",
"@aws-sdk/client-s3": "^3.689.0",
"@aws-sdk/s3-request-presigner": "^3.689.0",
"@elysiajs/cors": "1.1.0",
"@elysiajs/cron": "1.1.0",
"@elysiajs/html": "1.1.0",
Expand Down
50 changes: 23 additions & 27 deletions apps/backend/src/modules/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Context, Elysia, t } from "elysia"
import type { Session, User } from "lucia"
import { Lucia, generateIdFromEntropySize } from "lucia"
import { TimeSpan, createDate, isWithinExpirationDate } from "oslo"
import { Cookie } from "oslo/cookie"
import { alphabet, generateRandomString, sha256 } from "oslo/crypto"
import { encodeHex } from "oslo/encoding"
import { omit } from "radash"
Expand Down Expand Up @@ -182,8 +183,10 @@ export class Auth {
if (env.UNDB_DISABLE_REGISTRATION) {
this.logger.info("Registration is disabled")
if (!adminEmail || !adminPassword) {
this.logger.fatal("Registration is disabled but admin user is not set")
throw new Error("Registration is disabled but admin user is not set")
const message =
"Registration is disabled but admin user is not set, please set UNDB_ADMIN_EMAIL and UNDB_ADMIN_PASSWORD environment variables"
this.logger.fatal(message)
throw new Error(message)
}

const user = await this.queryBuilder
Expand Down Expand Up @@ -369,7 +372,8 @@ export class Auth {
},
{
beforeHandle(context) {
if (env.UNDB_DISABLE_REGISTRATION) {
const invitationId = context.body.invitationId
if (env.UNDB_DISABLE_REGISTRATION && !invitationId) {
return new Response(null, {
status: 403,
})
Expand Down Expand Up @@ -596,14 +600,12 @@ export class Auth {
"Invitation should exist",
)

const spaceId = invitation.spaceId

const cookieHeader = ctx.request.headers.get("Cookie") ?? ""
const sessionId = this.lucia.readSessionCookie(cookieHeader)
const { spaceId, email, role } = invitation

function redirectToSignupOrLogin(
path: "signup" | "login" = "signup",
email: string | undefined = invitation.email,
cookie?: Cookie,
) {
const search = new URLSearchParams()
search.set("invitationId", invitationId)
Expand All @@ -612,31 +614,25 @@ export class Auth {
}

const response = ctx.redirect(`/${path}?${search.toString()}`, 301)
if (cookie) {
response.headers.set("Set-Cookie", cookie.serialize())
}
return response
}

if (!sessionId) {
return redirectToSignupOrLogin()
}

const { user, session: validatedSession } = await this.lucia.validateSession(sessionId)
const user = await this.queryBuilder
.selectFrom("undb_user")
.selectAll()
.where("email", "=", email)
.executeTakeFirst()
if (!user) {
return redirectToSignupOrLogin()
}
if (invitation.email !== user.email) {
return redirectToSignupOrLogin("login")
return redirectToSignupOrLogin("signup", email)
} else {
await this.spaceMemberService.createMember(user.id, spaceId, role)
const session = await this.lucia.createSession(user.id, { space_id: spaceId })
const sessionCookie = this.lucia.createSessionCookie(session.id)
return redirectToSignupOrLogin("login", email, sessionCookie)
}

await this.spaceMemberService.createMember(user.id, spaceId, invitation.role)
const session = await this.lucia.createSession(user.id, { space_id: spaceId })
const sessionCookie = this.lucia.createSessionCookie(session.id)
return new Response(null, {
status: 302,
headers: {
Location: "/",
"Set-Cookie": sessionCookie.serialize(),
},
})
})
},
{
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2.0.3"
"@tauri-apps/api": "^2.1.1"
},
"devDependencies": {
"@tauri-apps/cli": "^1.6.3",
"typescript": "^5.6.3",
"vite": "^5.4.10"
"vite": "^5.4.11"
}
}
14 changes: 7 additions & 7 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"@sveltejs/kit": "^2.8.0",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/eslint-plugin-query": "^5.59.20",
"@tanstack/eslint-plugin-query": "^5.60.1",
"@types/eslint": "^8.56.12",
"@types/lodash.unzip": "^3.4.9",
"@types/papaparse": "^5.3.15",
"@types/sortablejs": "latest",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"@undb/commands": "workspace:*",
"@undb/domain": "workspace:*",
"@undb/formula": "workspace:*",
Expand All @@ -51,17 +51,17 @@
"houdini-svelte": "^1.2.64",
"lodash.unzip": "^3.4.0",
"papaparse": "^5.4.1",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"postcss-load-config": "^6.0.1",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
"prettier-plugin-svelte": "^3.2.8",
"prettier-plugin-tailwindcss": "^0.6.8",
"radash": "^12.1.0",
"rollup-plugin-visualizer": "^5.12.0",
"safe-flat": "^2.1.0",
"sortablejs": "^1.15.3",
"svelte": "^4.2.19",
"svelte-check": "^4.0.5",
"svelte-check": "^4.0.7",
"svelte-headless-table": "^0.18.3",
"svelte-inview": "^4.0.4",
"svelte-jsoneditor": "^1.1.2",
Expand All @@ -73,7 +73,7 @@
"tslib": "^2.8.1",
"type-fest": "^4.26.1",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite": "^5.4.11",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.1.4",
"xlsx": "^0.18.5"
Expand Down
18 changes: 16 additions & 2 deletions apps/frontend/src/lib/components/blocks/auth/signup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { Separator } from "$lib/components/ui/separator"
import PasswordInput from "$lib/components/ui/input/password-input.svelte"
import { LoaderCircleIcon } from "lucide-svelte"
import { cn } from "$lib/utils"
export let redirect: string | null
export let invitationId: string | null
Expand Down Expand Up @@ -113,8 +114,21 @@
<div class="grid gap-2">
<Form.Field {form} name="email">
<Form.Control let:attrs>
<Form.Label for="email">Email</Form.Label>
<Input {...attrs} id="email" type="email" placeholder="Enter your work email" bind:value={$formData.email} />
<Form.Label for="email"
>Email
{#if invitationId}
<span class="text-green-500"> (Invited)</span>
{/if}
</Form.Label>
<Input
{...attrs}
disabled={!!invitationId}
id="email"
type="email"
class={cn(!!invitationId && "border-2 border-green-500")}
placeholder="Enter your work email"
bind:value={$formData.email}
/>
</Form.Control>
<Form.Description />
<Form.FieldErrors />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<Sheet.Footer class={cn("border-t px-6 pt-4", $match ? "flex-col space-y-2" : "")}>
<Button variant="outline" type="button" on:click={() => closeModal(CREATE_RECORD_MODAL)}>Cancel</Button>
<Button disabled={$isMutating > 0} type="submit" form="createRecord">
<Button disabled={$isMutating > 0 || disabled} type="submit" form="createRecord">
{#if $isMutating > 0}
<LoaderCircleIcon class="mr-2 h-5 w-5 animate-spin" />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { useMediaQuery } from "$lib/store/media-query.store"
import IdControl from "../field-control/id-control.svelte"
import type { ICreateRecordCommandOutput } from "@undb/commands"
import { onMount } from "svelte"
// beforeNavigate(({ cancel }) => {
// if ($tainted) {
Expand Down Expand Up @@ -65,11 +66,24 @@
})
}
$: defaultValue = {
...$table.getDefaultValues(formId ? new FormIdVO(formId) : undefined, $defaultRecordValues ?? undefined),
[ID_TYPE]: null,
let defaultValue: any = {}
function setDefaultValue() {
defaultValue = {
...$table.getDefaultValues(formId ? new FormIdVO(formId) : undefined, $defaultRecordValues ?? undefined),
[ID_TYPE]: null,
}
form.reset({ data: defaultValue })
}
$: if ($defaultRecordValues) {
setDefaultValue()
}
onMount(() => {
setDefaultValue()
})
const form = superForm(defaults(defaultValue, zodClient(schema)), {
SPA: true,
dataType: "json",
Expand All @@ -79,9 +93,13 @@
onSubmit(event) {
validateForm({ update: true })
},
onChange(event) {
validateForm({ update: true })
},
onUpdate(event) {
if (!event.form.valid) {
console.log(event.form.errors, event.form.data)
console.log(event.form.errors)
console.log(event.form.data)
return
}
Expand All @@ -91,10 +109,9 @@
const { form: formData, enhance, allErrors, tainted, errors, validateForm } = form
$: defaultValue, form.reset({ data: defaultValue })
$: dirty = !!$tainted
$: disabled = !!$allErrors.length
$: console.log($allErrors)
$: fields = $table
.getOrderedMutableFields(formId ? new FormIdVO(formId) : undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
mutationKey: ["record", tableId, field.id.value, recordId],
mutationFn: trpc.record.update.mutate,
async onSuccess(data, variables) {
console.log(variables)
const value = variables.values[field.id.value]
if (isUserFieldMacro(value)) {
await store.invalidateRecord($table, recordId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<KeyIcon class="mr-2 h-4 w-4" />
Api Token
</DropdownMenu.Item>
<DropdownMenu.Item href="https://template.undb.io" target="_blank" rel="noopener noreferrer">
<DropdownMenu.Item href="https://undb.io/templates" target="_blank" rel="noopener noreferrer">
<img src={Logo} alt="undb" class="mr-2 h-4 w-4" />
Undb Templates
<ExternalLinkIcon class="ml-auto h-4 w-4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
validators: zodClient(schema),
resetForm: false,
invalidateAll: false,
onSubmit(input) {
validateForm({ update: true })
},
onChange(event) {
validateForm({ update: true })
},
onUpdate(event) {
if (!event.form.valid) {
return
Expand All @@ -93,7 +99,7 @@
},
})
const { form: formData, enhance, allErrors, tainted, reset, errors } = form
const { form: formData, enhance, allErrors, tainted, reset, errors, validateForm } = form
$: mutableFields = fields.filter((f) => f.isMutable)
$: taintedKeys = Object.keys($tainted ?? {})
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/routes/(auth)/signup/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { GetSignupSettingsStore } from "$houdini"
import { redirect } from "@sveltejs/kit"
import type { LayoutLoad } from "./$types"

export const load: LayoutLoad = async () => {
export const load: LayoutLoad = async (event) => {
const store = new GetSignupSettingsStore()

const data = await store.fetch({ policy: "NetworkOnly" })
const invitationId = event.url.searchParams.get("invitationId")

const registrationEnabled = !!data.data?.settings?.registration?.enabled
if (!registrationEnabled) {
if (!registrationEnabled && !invitationId) {
throw redirect(302, "/login")
}

Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ services:
- UNDB_VERIFY_EMAIL=true
- UNDB_MAIL_HOST=maildev
- UNDB_MAIL_PORT=1025
- UNDB_DISABLE_REGISTRATION=true
- [email protected]
- UNDB_ADMIN_PASSWORD=admin
depends_on:
- db
- minio
Expand Down
11 changes: 11 additions & 0 deletions drizzle.turso.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from "drizzle-kit"

export default defineConfig({
schema: "./packages/persistence/src/tables.ts",
out: "./apps/backend/drizzle",
dialect: "turso",
tablesFilter: ["undb_*"],
dbCredentials: {
url: process.env.UNDB_DB_TURSO_URL!,
},
})
Loading

0 comments on commit 5a3b9ad

Please sign in to comment.