Skip to content

Commit 1d98f05

Browse files
committed
fix: register and login
1 parent 3a2924a commit 1d98f05

48 files changed

Lines changed: 716 additions & 452 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/new-deepnotes-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ jobs:
2525
POSTGRES_PASSWORD: deepnotes
2626
POSTGRES_DB: deepnotes
2727
ports:
28-
- 5433:5432
28+
- 5432:5432
2929
options: >-
3030
--health-cmd "pg_isready -U deepnotes -d deepnotes"
3131
--health-interval 5s
3232
--health-timeout 5s
3333
--health-retries 10
3434
env:
35-
DATABASE_URL: postgresql://deepnotes:deepnotes@127.0.0.1:5433/deepnotes
35+
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/deepnotes
3636
# CREATEDB-capable catalog connection for @deepnotes/db template-clone tests (RESTART_PLAN §5.7)
37-
DATABASE_ADMIN_URL: postgresql://deepnotes:deepnotes@127.0.0.1:5433/postgres
37+
DATABASE_ADMIN_URL: postgresql://postgres:postgres@127.0.0.1:5432/postgres
3838
steps:
3939
- uses: actions/checkout@v4
4040

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { createDb, type DeepnotesDb } from "@deepnotes/db/client";
22

3-
let cachedConn: string | undefined;
4-
let cachedDb: DeepnotesDb | undefined;
5-
6-
/** One Drizzle instance per isolate; Hyperdrive URL is stable for the binding. */
3+
/** Create a new Drizzle instance per request to avoid Cloudflare Workers I/O isolation issues. */
74
export function getDbForConnectionString(connectionString: string): DeepnotesDb {
8-
if (cachedDb != null && cachedConn === connectionString) {
9-
return cachedDb;
10-
}
11-
cachedConn = connectionString;
12-
cachedDb = createDb(connectionString);
13-
return cachedDb;
5+
return createDb(connectionString);
146
}

new-deepnotes/apps/api-worker/src/routes/users.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ app.post("/api/users", async (c) => {
5050

5151
const parsed = userRegisterRequestSchema.safeParse(bodyJson);
5252
if (!parsed.success) {
53+
const flattened = parsed.error.flatten();
54+
const formErrors = flattened.formErrors.join("; ");
55+
const fieldErrors = Object.entries(flattened.fieldErrors)
56+
.map(([field, errors]) => `${field}: ${errors?.join(", ")}`)
57+
.join("; ");
58+
const message = [formErrors, fieldErrors].filter(Boolean).join("; ") || "Invalid request data";
5359
return c.json(
5460
{
5561
code: "VALIDATION_ERROR",
56-
message: parsed.error.flatten().formErrors.join("; "),
62+
message,
5763
},
5864
400,
5965
);

new-deepnotes/apps/api-worker/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ service = "deepnotes-api"
2828
[[hyperdrive]]
2929
binding = "HYPERDRIVE"
3030
id = "00000000-0000-0000-0000-000000000000"
31-
localConnectionString = "postgresql://deepnotes:deepnotes@127.0.0.1:5433/deepnotes"
31+
localConnectionString = "postgresql://postgres:postgres@127.0.0.1:5432/deepnotes"
3232

3333
# Daily cleanup of soft-deleted pages and groups past their grace period.
3434
[[triggers.crons]]

new-deepnotes/apps/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"clsx": "^2.1.1",
4848
"highlight.js": "^11.11.1",
4949
"katex": "0.16.22",
50-
"libsodium-wrappers-sumo": "^0.8.0",
5150
"lowlight": "3.3.0",
5251
"lucide-vue-next": "^1.0.0",
5352
"msgpackr": "^1.11.2",

new-deepnotes/apps/web/src/features/auth/build-user-register.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
ensureSodiumReady,
66
wrapKeyPair,
77
type KeyPair,
8+
generateKeyPair,
89
} from "@deepnotes/e2ee";
910
import { pack } from "msgpackr";
10-
import sodium from "libsodium-wrappers-sumo";
1111
import { nanoid } from "nanoid";
1212

1313
import type { components } from "../../api/api-types.generated";
@@ -41,7 +41,7 @@ function buildPersonalGroupCreation(input: {
4141
const internalKeyring = createSymmetricKeyring();
4242
const contentKeyring = createSymmetricKeyring();
4343

44-
const rawGroupKeys = sodium.crypto_box_keypair();
44+
const rawGroupKeys = generateKeyPair();
4545
const groupPublicRing = createKeyring(rawGroupKeys.publicKey);
4646
const groupPrivateRing = createPrivateKeyring(rawGroupKeys.privateKey);
4747

@@ -113,7 +113,7 @@ export async function buildUserRegisterRequest(input: {
113113
const pageId = nanoid();
114114
const displayName = input.displayName ?? "";
115115

116-
const rawUserKeys = sodium.crypto_box_keypair();
116+
const rawUserKeys = generateKeyPair();
117117
const userPublicKeyring = createKeyring(rawUserKeys.publicKey);
118118
const userPrivateKeyring = createPrivateKeyring(rawUserKeys.privateKey);
119119
const userKeyPair = wrapKeyPair(userPublicKeyring, userPrivateKeyring);

new-deepnotes/apps/web/src/features/groups/group-make-private-crypto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
ensureSodiumReady,
88
wrapKeyPair,
99
wrapSymmetricKey,
10+
generateKeyPair,
1011
} from "@deepnotes/e2ee";
11-
import sodium from "libsodium-wrappers-sumo";
1212

1313
import { uint8ToBase64 } from "../auth/bytes";
1414
import type { StoredSessionCrypto } from "../auth/crypto-storage";
@@ -122,7 +122,7 @@ export async function buildGroupPrivacyMakePrivateRequest(input: {
122122
const newGroupInternalKeyring = oldGroupInternalKeyring.addKey();
123123
const newGroupContentKeyring = oldGroupContentKeyring.addKey();
124124

125-
const newGroupRawKeypair = sodium.crypto_box_keypair();
125+
const newGroupRawKeypair = generateKeyPair();
126126
const newGroupPublicKeyring = oldGroupPublicKeyring.addKey(
127127
newGroupRawKeypair.publicKey,
128128
);

new-deepnotes/apps/web/vite.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export default defineConfig({
2525
},
2626
},
2727
},
28-
optimizeDeps: {
29-
include: ["libsodium-wrappers-sumo"],
30-
},
3128
test: {
3229
environment: "happy-dom",
3330
include: ["src/**/*.test.ts"],

new-deepnotes/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
postgres:
33
image: postgres:16-alpine
44
ports:
5-
- "5433:5432"
5+
- "5432:5432"
66
environment:
77
POSTGRES_USER: deepnotes
88
POSTGRES_PASSWORD: deepnotes

new-deepnotes/docs/DEPLOY_CLOUDFLARE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Typical pattern:
3636

3737
### Local
3838

39-
See `template.env` and `docker-compose.yml`: Postgres on `5433`, Redis on `6380`, `DATABASE_URL`, optional `DATABASE_ADMIN_URL` for template DB tests.
39+
See `template.env` and `docker-compose.yml`: Postgres on `5432`, Redis on `6380`, `DATABASE_URL`, optional `DATABASE_ADMIN_URL` for template DB tests.
4040

4141
## CI
4242

0 commit comments

Comments
 (0)