Fix sign in, sign out, dan register localhost:3000
This commit is contained in:
@@ -1,16 +1,11 @@
|
|||||||
import { betterAuth } from "better-auth";
|
import { betterAuth } from "better-auth";
|
||||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||||
import { PrismaClient } from "../../generated/prisma";
|
import { PrismaClient } from "../../generated/prisma";
|
||||||
import logger from "./logger";
|
import { VITE_PUBLIC_URL } from "./env";
|
||||||
|
|
||||||
const baseUrl = process.env.VITE_PUBLIC_URL;
|
const baseUrl = VITE_PUBLIC_URL;
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
if (!baseUrl) {
|
|
||||||
logger.error("VITE_PUBLIC_URL is not defined");
|
|
||||||
throw new Error("VITE_PUBLIC_URL is not defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
// logger.info('Initializing Better Auth with Prisma adapter');
|
// logger.info('Initializing Better Auth with Prisma adapter');
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
baseURL: baseUrl,
|
baseURL: baseUrl,
|
||||||
|
|||||||
@@ -20,10 +20,17 @@ export const getEnv = (key: string, defaultValue = ""): string => {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VITE_PUBLIC_URL = getEnv(
|
export const VITE_PUBLIC_URL = (() => {
|
||||||
"VITE_PUBLIC_URL",
|
const envUrl = getEnv("VITE_PUBLIC_URL");
|
||||||
"http://localhost:3000",
|
if (envUrl) return envUrl;
|
||||||
);
|
|
||||||
|
// Fallback for browser
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
return window.location.origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "http://localhost:3000";
|
||||||
|
})();
|
||||||
|
|
||||||
export const IS_DEV = (() => {
|
export const IS_DEV = (() => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user