[GH-ISSUE #1396] [Astro] production build cannot connect to turso db #17360

Closed
opened 2026-04-15 15:29:50 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jonaspm on GitHub (Feb 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1396

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create an astro 5 project,
  "dependencies": {
    "@astrojs/db": "0.14.6",
    "@astrojs/node": "^9.0.2",
    "@astrojs/ts-plugin": "^1.10.4",
    "astro": "^5.2.5",
    "better-auth": "^1.1.16",
    "ulidx": "^2.4.1",
  },
  "devDependencies": {
    "@types/bun": "^1.2.2",
    "drizzle-kit": "^0.29.1",
    "oxlint": "^0.15.10",
    "typescript": "^5.7.3",
  },
  "overrides": {
    "drizzle-orm": "0.37.0"
  },
  1. Setup better-auth
  2. Setup a button for login with Facebook
  3. Define env vars: ASTRO_DB_APP_TOKEN, ASTRO_DB_REMOTE_URL, BETTER_AUTH_SECRET, BETTER_AUTH_TRUSTED_ORIGINS, PUBLIC_BASE_URL
  4. bun run build
  5. bun run preview
  6. Go to browser, click the login with facebook button, after facebook redirects back to localhost, error shows up.

Current vs. Expected behavior

Expected:
Successful login with facebook

Current behaviour:

$ bun run --bun astro preview
14:25:06 [@astrojs/node] Server listening on 
  local: https://localhost:3333
  network: https://192.168.31.239:3333

2025-02-09T20:25:19.666Z ERROR [Better Auth]: Better auth was unable to query your database.
Error:  23 |             node[pathChunk] = {};
24 |           }
25 |           node = node[pathChunk];
26 |         } else {
27 |           const rawValue = row[columnIndex];
28 |           const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
                                                                                  ^
SyntaxError: JSON Parse error: Unexpected identifier "roles"
      at <parse> (C:\Users\jonaspm\Development\repos\project\node_modules\drizzle-orm\utils.js:28:78)

Image

What version of Better Auth are you using?

1.1.16

Provide environment information

- OS: Windows 11 x64
- Browser: Firefox 134.0.2
- Runtime: Bun 1.2.2

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { magicLink } from 'better-auth/plugins';
import { Account, db, Session, User, Verification, } from 'astro:db';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { ulid } from 'ulidx';

export const auth = betterAuth({
    secret: import.meta.env.BETTER_AUTH_SECRET,
    baseURL: import.meta.env.PUBLIC_BASE_URL,
    account: {
        accountLinking: {
            enabled: true,
            trustedProviders: ['facebook', 'google'],
        }
    },
    database: drizzleAdapter(db, {
        provider: 'sqlite',
        schema: {
            user: User,
            session: Session,
            account: Account,
            verification: Verification,
        }
    }),
    advanced: {
        generateId: () => ulid(),
    },
    emailAndPassword: {
        enabled: true,
    },
    trustedOrigins: [
        import.meta.env.BETTER_AUTH_TRUSTED_ORIGINS
    ],
    socialProviders: {
        google: {
            clientId: import.meta.env.GOOGLE_CLIENT_ID as string,
            clientSecret: import.meta.env.GOOGLE_CLIENT_SECRET as string
        },
        facebook: {
            clientId: import.meta.env.FACEBOOK_CLIENT_ID as string,
            clientSecret: import.meta.env.FACEBOOK_CLIENT_SECRET as string
        }
    },
    plugins: [
        magicLink({
            sendMagicLink: async ({email, token, url }, request) => {
                // Send the magic link to the user's email
                console.debug(`Sending magic link to ${email}`, token, url);
            }
        })
    ]
});

Additional context

No response

Originally created by @jonaspm on GitHub (Feb 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1396 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create an astro 5 project, ```json "dependencies": { "@astrojs/db": "0.14.6", "@astrojs/node": "^9.0.2", "@astrojs/ts-plugin": "^1.10.4", "astro": "^5.2.5", "better-auth": "^1.1.16", "ulidx": "^2.4.1", }, "devDependencies": { "@types/bun": "^1.2.2", "drizzle-kit": "^0.29.1", "oxlint": "^0.15.10", "typescript": "^5.7.3", }, "overrides": { "drizzle-orm": "0.37.0" }, ``` 2. Setup better-auth 3. Setup a button for login with Facebook 4. Define env vars: ASTRO_DB_APP_TOKEN, ASTRO_DB_REMOTE_URL, BETTER_AUTH_SECRET, BETTER_AUTH_TRUSTED_ORIGINS, PUBLIC_BASE_URL 5. bun run build 6. bun run preview 7. Go to browser, click the login with facebook button, after facebook redirects back to localhost, error shows up. ### Current vs. Expected behavior Expected: Successful login with facebook Current behaviour: ```bash $ bun run --bun astro preview 14:25:06 [@astrojs/node] Server listening on local: https://localhost:3333 network: https://192.168.31.239:3333 2025-02-09T20:25:19.666Z ERROR [Better Auth]: Better auth was unable to query your database. Error: 23 | node[pathChunk] = {}; 24 | } 25 | node = node[pathChunk]; 26 | } else { 27 | const rawValue = row[columnIndex]; 28 | const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue); ^ SyntaxError: JSON Parse error: Unexpected identifier "roles" at <parse> (C:\Users\jonaspm\Development\repos\project\node_modules\drizzle-orm\utils.js:28:78) ``` ![Image](https://github.com/user-attachments/assets/1b58cfed-98be-4c35-a4d9-42d5f0e6b832) ### What version of Better Auth are you using? 1.1.16 ### Provide environment information ```bash - OS: Windows 11 x64 - Browser: Firefox 134.0.2 - Runtime: Bun 1.2.2 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { magicLink } from 'better-auth/plugins'; import { Account, db, Session, User, Verification, } from 'astro:db'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { ulid } from 'ulidx'; export const auth = betterAuth({ secret: import.meta.env.BETTER_AUTH_SECRET, baseURL: import.meta.env.PUBLIC_BASE_URL, account: { accountLinking: { enabled: true, trustedProviders: ['facebook', 'google'], } }, database: drizzleAdapter(db, { provider: 'sqlite', schema: { user: User, session: Session, account: Account, verification: Verification, } }), advanced: { generateId: () => ulid(), }, emailAndPassword: { enabled: true, }, trustedOrigins: [ import.meta.env.BETTER_AUTH_TRUSTED_ORIGINS ], socialProviders: { google: { clientId: import.meta.env.GOOGLE_CLIENT_ID as string, clientSecret: import.meta.env.GOOGLE_CLIENT_SECRET as string }, facebook: { clientId: import.meta.env.FACEBOOK_CLIENT_ID as string, clientSecret: import.meta.env.FACEBOOK_CLIENT_SECRET as string } }, plugins: [ magicLink({ sendMagicLink: async ({email, token, url }, request) => { // Send the magic link to the user's email console.debug(`Sending magic link to ${email}`, token, url); } }) ] }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 15:29:50 -05:00
Author
Owner

@jonaspm commented on GitHub (Feb 12, 2025):

Note: the schema was not up to date

<!-- gh-comment-id:2654858444 --> @jonaspm commented on GitHub (Feb 12, 2025): Note: the schema was not up to date
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17360