Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ import type { NextConfig } from "next";
// client-reference manifests and route transitions. See docs:
// https://nextjs.org/docs/app/building-your-application/configuring
const nextConfig: NextConfig = {
async rewrites() {
const rawApiUrl = process.env.NEXT_PUBLIC_API_URL;
if (!rawApiUrl || !/^https?:\/\//i.test(rawApiUrl)) {
return [];
}

const normalized = rawApiUrl.replace(/\/$/, '');
return [
{
source: '/api/:path*',
destination: `${normalized}/:path*`,
},
];
},
async headers() {
return [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"node": ">=20 <21"
},
"scripts": {
"dev": "next dev",
"dev": "next dev --webpack",
"build": "next build --webpack",
"start": "next start",
"lint": "next lint"
Expand Down
4 changes: 3 additions & 1 deletion src/components/auth/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChevronLeftIcon, EyeCloseIcon, EyeIcon } from "@/icons";
import Link from "next/link";
import React, { useState, useEffect } from "react";
import { apiClient } from "@/lib/api-client";
import { getApiBaseUrl } from "@/lib/api";
import { useRouter, useSearchParams } from "next/navigation";

export default function SignInForm() {
Expand Down Expand Up @@ -60,7 +61,8 @@ export default function SignInForm() {
try {
// Redirect to backend Google OAuth endpoint
const redirectUrl = `${window.location.origin}/auth/callback`;
window.location.href = `${process.env.NEXT_PUBLIC_API_URL}/auth/google?redirect_uri=${encodeURIComponent(redirectUrl)}&next=${encodeURIComponent(nextDest)}`;
const apiBaseUrl = getApiBaseUrl();
window.location.href = `${apiBaseUrl}/auth/google?redirect_uri=${encodeURIComponent(redirectUrl)}&next=${encodeURIComponent(nextDest)}`;
} catch (err) {
const error = err as { message?: string };
setError(error?.message || "Google sign-in failed. Please try again.");
Expand Down
4 changes: 3 additions & 1 deletion src/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Replaces Supabase client for authentication and data operations
*/

const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api';
import { getApiBaseUrl } from "@/lib/api";

const API_URL = getApiBaseUrl();

export interface AuthResponse {
token: string;
Expand Down
6 changes: 5 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const RESOURCE_PATH_MAP: Record<string, string> = {
const normalizePath = (path: string) => RESOURCE_PATH_MAP[path] || path;

export const getApiBaseUrl = (): string => {
return (process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_BASE_URL).replace(/\/$/, '');
const rawBaseUrl = (process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_BASE_URL).replace(/\/$/, '');
if (typeof window !== 'undefined' && /^https?:\/\//i.test(rawBaseUrl)) {
return '/api';
}
return rawBaseUrl;
};

export const toApiUrl = (pathOrUrl: string): string => {
Expand Down
Loading