fix: env missing on migrate

This commit is contained in:
Bereket Engida
2024-10-14 03:30:53 +03:00
parent 9316a0a2f0
commit 54d01b21fe
6 changed files with 23 additions and 90 deletions

View File

@@ -32,7 +32,7 @@ export default function Component() {
code: totpCode, code: totpCode,
}) })
.then((res) => { .then((res) => {
if (res.data?.status) { if (res.data?.session) {
setSuccess(true); setSuccess(true);
setError(""); setError("");
} else { } else {

View File

@@ -15,15 +15,20 @@ import { resend } from "./email/resend";
const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev"; const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev";
const to = process.env.TEST_EMAIL || ""; const to = process.env.TEST_EMAIL || "";
const libsql = new LibsqlDialect({
url: process.env.TURSO_DATABASE_URL || "",
authToken: process.env.TURSO_AUTH_TOKEN || "",
});
export const auth = betterAuth({ export const auth = betterAuth({
database: new LibsqlDialect({ database: {
url: process.env.TURSO_DATABASE_URL || "", dialect: libsql,
authToken: process.env.TURSO_AUTH_TOKEN || "", type: "sqlite",
}), },
emailAndPassword: { emailAndPassword: {
enabled: true, enabled: true,
async sendResetPassword(url, user) { async sendResetPassword(url, user) {
const res = await resend.emails.send({ await resend.emails.send({
from, from,
to: user.email, to: user.email,
subject: "Reset your password", subject: "Reset your password",
@@ -86,82 +91,6 @@ export const auth = betterAuth({
bearer(), bearer(),
admin(), admin(),
], ],
session: {
additionalFields: {
latitude: {
type: "string",
required: false,
},
longitude: {
type: "string",
required: false,
},
continent: {
type: "string",
required: false,
},
country: {
type: "string",
required: false,
},
region: {
type: "string",
required: false,
},
city: {
type: "string",
required: false,
},
timezone: {
type: "string",
required: false,
},
browserName: {
type: "string",
required: false,
},
browserVersion: {
type: "string",
required: false,
},
browserMajor: {
type: "string",
required: false,
},
engineName: {
type: "string",
required: false,
},
engineVersion: {
type: "string",
required: false,
},
osName: {
type: "string",
required: false,
},
osVersion: {
type: "string",
required: false,
},
deviceVendor: {
type: "string",
required: false,
},
deviceModel: {
type: "string",
required: false,
},
deviceType: {
type: "string",
required: false,
},
cpuArchitecture: {
type: "string",
required: false,
},
},
},
socialProviders: { socialProviders: {
github: { github: {
clientId: process.env.GITHUB_CLIENT_ID || "", clientId: process.env.GITHUB_CLIENT_ID || "",
@@ -181,5 +110,3 @@ export const auth = betterAuth({
}, },
}, },
}); });
type A = typeof auth.$Infer.Session;

View File

@@ -3,11 +3,11 @@
"version": "0.4.9-beta.1", "version": "0.4.9-beta.1",
"description": "The most comprehensive authentication library for TypeScript.", "description": "The most comprehensive authentication library for TypeScript.",
"type": "module", "type": "module",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/better-auth/better-auth", "url": "https://github.com/better-auth/better-auth",
"directory": "packages/better-auth" "directory": "packages/better-auth"
}, },
"scripts": { "scripts": {
"build": "NODE_OPTIONS='--max-old-space-size=4000' tsup --clean --dts", "build": "NODE_OPTIONS='--max-old-space-size=4000' tsup --clean --dts",
"dev": "NODE_OPTIONS='--max-old-space-size=4000' tsup --watch --sourcemap", "dev": "NODE_OPTIONS='--max-old-space-size=4000' tsup --watch --sourcemap",
@@ -98,6 +98,7 @@
"commander": "^12.1.0", "commander": "^12.1.0",
"consola": "^3.2.3", "consola": "^3.2.3",
"defu": "^6.1.4", "defu": "^6.1.4",
"dotenv": "^16.4.5",
"kysely": "^0.27.4", "kysely": "^0.27.4",
"nanoid": "^5.0.7", "nanoid": "^5.0.7",
"nanostores": "^0.11.2", "nanostores": "^0.11.2",

View File

@@ -43,9 +43,10 @@ export const migrate = new Command("migrate")
return; return;
} }
const db = await createKyselyAdapter(config).catch((e) => { const db = await createKyselyAdapter(config).catch((e) => {
logger.error(e.message); logger.error(e);
process.exit(1); process.exit(1);
}); });
if (!db) { if (!db) {
logger.error( logger.error(
"Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.", "Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.",

View File

@@ -3,6 +3,7 @@
import { Command } from "commander"; import { Command } from "commander";
import { migrate } from "./commands/migrate"; import { migrate } from "./commands/migrate";
import { generate } from "./commands/generate"; import { generate } from "./commands/generate";
import "dotenv/config";
async function main() { async function main() {
const program = new Command().name("better-auth"); const program = new Command().name("better-auth");

3
pnpm-lock.yaml generated
View File

@@ -1480,6 +1480,9 @@ importers:
defu: defu:
specifier: ^6.1.4 specifier: ^6.1.4
version: 6.1.4 version: 6.1.4
dotenv:
specifier: ^16.4.5
version: 16.4.5
kysely: kysely:
specifier: ^0.27.4 specifier: ^0.27.4
version: 0.27.4 version: 0.27.4