......
This commit is contained in:
@@ -3,11 +3,30 @@
|
||||
// Helper function to verify authentication with the local API
|
||||
export async function verifyAuth(token: string) {
|
||||
try {
|
||||
// Use a properly formed URL with origin
|
||||
const origin = typeof window !== 'undefined' ? window.location.origin : '';
|
||||
const authEndpoint = new URL('/api/auth/me', origin).toString();
|
||||
let authEndpoint;
|
||||
|
||||
console.log(`Verifying auth with ${authEndpoint} using token: ${token.substring(0, 10)}...`);
|
||||
// Check if we're running in a browser environment
|
||||
if (typeof window !== 'undefined') {
|
||||
// Use the current origin in 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 {
|
||||
// For SSR or when window is not available (e.g. in Docker container)
|
||||
// Use the environment variable if available
|
||||
if (process.env.SERVER_API_URL) {
|
||||
authEndpoint = `${process.env.SERVER_API_URL}/auth/me`;
|
||||
console.log(`Using SERVER_API_URL for auth endpoint: ${authEndpoint}`);
|
||||
} else {
|
||||
// Fallback for local development
|
||||
const protocol = (process.env.USE_HTTPS === 'false') ? 'http' : 'https';
|
||||
const port = process.env.INTERNAL_API_PORT || '3000';
|
||||
authEndpoint = `${protocol}://localhost:${port}/api/auth/me`;
|
||||
console.log(`Using fallback for auth endpoint: ${authEndpoint}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Verifying authentication with endpoint: ${authEndpoint}`);
|
||||
|
||||
const response = await fetch(authEndpoint, {
|
||||
method: "GET",
|
||||
|
||||
Reference in New Issue
Block a user