nextjs-rewrite (#5)
Reviewed-on: #5 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { createAuthClient } from "better-auth/client";
|
||||
|
||||
// Get base URL from environment or use localhost as fallback
|
||||
const getBaseURL = () => {
|
||||
if (typeof window === 'undefined') {
|
||||
return process.env.BETTER_AUTH_URL || "http://localhost:3000";
|
||||
}
|
||||
|
||||
// For client-side, use the current origin but allow localhost variations
|
||||
const origin = window.location.origin;
|
||||
if (origin.includes('localhost') || origin.includes('127.0.0.1') || origin.includes('0.0.0.0')) {
|
||||
return "http://localhost:3000"; // Normalize to localhost for Better Auth
|
||||
}
|
||||
|
||||
return origin;
|
||||
};
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
baseURL: getBaseURL(),
|
||||
});
|
||||
Reference in New Issue
Block a user