Update auth-helpers.ts
This commit is contained in:
@@ -4,18 +4,37 @@
|
|||||||
export async function verifyAuth(token: string) {
|
export async function verifyAuth(token: string) {
|
||||||
try {
|
try {
|
||||||
let authEndpoint;
|
let authEndpoint;
|
||||||
|
const torMode = process.env.NEXT_PUBLIC_TOR_MODE === 'true';
|
||||||
|
|
||||||
// Check if we're running in a browser environment
|
// Check if we're running in a browser environment
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
// Use the current origin in browser environments
|
// For Tor mode in browser, prefer relative URLs
|
||||||
const origin = window.location.origin;
|
if (torMode) {
|
||||||
authEndpoint = new URL('/api/auth/me', origin).toString();
|
authEndpoint = '/api/auth/me';
|
||||||
console.log(`Using browser origin for auth endpoint: ${authEndpoint}`);
|
console.log(`Tor mode: Using relative URL for auth endpoint: ${authEndpoint}`);
|
||||||
|
} else {
|
||||||
|
// Use the current origin in regular browser environments
|
||||||
|
const origin = window.location.origin;
|
||||||
|
authEndpoint = new URL('/api/auth/me', origin).toString();
|
||||||
|
console.log(`Using browser origin for auth endpoint: ${authEndpoint}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For SSR or when window is not available (e.g. in Docker container)
|
// For SSR or when window is not available (e.g. in Docker container)
|
||||||
|
|
||||||
|
// For Tor mode, always use relative URLs
|
||||||
|
if (torMode) {
|
||||||
|
authEndpoint = '/api/auth/me';
|
||||||
|
console.log(`Tor mode SSR: Using relative URL for auth endpoint: ${authEndpoint}`);
|
||||||
|
}
|
||||||
// Use the environment variable if available
|
// Use the environment variable if available
|
||||||
if (process.env.SERVER_API_URL) {
|
else if (process.env.SERVER_API_URL) {
|
||||||
authEndpoint = `${process.env.SERVER_API_URL}/auth/me`;
|
// If SERVER_API_URL already includes /auth/me, don't append it again
|
||||||
|
if (process.env.SERVER_API_URL.includes('/auth/me')) {
|
||||||
|
authEndpoint = process.env.SERVER_API_URL;
|
||||||
|
} else {
|
||||||
|
// Otherwise append the endpoint to the base URL
|
||||||
|
authEndpoint = `${process.env.SERVER_API_URL}/auth/me`;
|
||||||
|
}
|
||||||
console.log(`Using SERVER_API_URL for auth endpoint: ${authEndpoint}`);
|
console.log(`Using SERVER_API_URL for auth endpoint: ${authEndpoint}`);
|
||||||
} else {
|
} else {
|
||||||
// Fallback for local development
|
// Fallback for local development
|
||||||
|
|||||||
Reference in New Issue
Block a user