mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-07 03:56:46 +03:00
updates to auth url
This commit is contained in:
@@ -18,6 +18,7 @@ DATABASE_URL=sqlite://data/gitea-mirror.db
|
|||||||
# Generate with: openssl rand -base64 32
|
# Generate with: openssl rand -base64 32
|
||||||
BETTER_AUTH_SECRET=change-this-to-a-secure-random-string-in-production
|
BETTER_AUTH_SECRET=change-this-to-a-secure-random-string-in-production
|
||||||
BETTER_AUTH_URL=http://localhost:4321
|
BETTER_AUTH_URL=http://localhost:4321
|
||||||
|
# PUBLIC_BETTER_AUTH_URL=https://your-domain.com # Optional: Set this if accessing from different origins (e.g., IP and domain)
|
||||||
# ENCRYPTION_SECRET=optional-encryption-key-for-token-encryption # Generate with: openssl rand -base64 48
|
# ENCRYPTION_SECRET=optional-encryption-key-for-token-encryption # Generate with: openssl rand -base64 48
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|||||||
@@ -4,9 +4,20 @@ import { ssoClient } from "@better-auth/sso/client";
|
|||||||
import type { Session as BetterAuthSession, User as BetterAuthUser } from "better-auth";
|
import type { Session as BetterAuthSession, User as BetterAuthUser } from "better-auth";
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
// The base URL is optional when running on the same domain
|
// Use PUBLIC_BETTER_AUTH_URL if set (for multi-origin access), otherwise use current origin
|
||||||
// Better Auth will use the current domain by default
|
// This allows the client to connect to the auth server even when accessed from different origins
|
||||||
baseURL: typeof window !== 'undefined' ? window.location.origin : 'http://localhost:4321',
|
baseURL: (() => {
|
||||||
|
// Check for public environment variable first (for client-side access)
|
||||||
|
if (typeof import.meta !== 'undefined' && import.meta.env?.PUBLIC_BETTER_AUTH_URL) {
|
||||||
|
return import.meta.env.PUBLIC_BETTER_AUTH_URL;
|
||||||
|
}
|
||||||
|
// Fall back to current origin if running in browser
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
return window.location.origin;
|
||||||
|
}
|
||||||
|
// Default for SSR
|
||||||
|
return 'http://localhost:4321';
|
||||||
|
})(),
|
||||||
basePath: '/api/auth', // Explicitly set the base path
|
basePath: '/api/auth', // Explicitly set the base path
|
||||||
plugins: [
|
plugins: [
|
||||||
oidcClient(),
|
oidcClient(),
|
||||||
|
|||||||
Reference in New Issue
Block a user