Compare commits
No commits in common. "787fff6bb02a9de2383d4a0f985e444de222ae9f" and "acb1ed1fd3493905d93e201faa435c48dd693265" have entirely different histories.
787fff6bb0
...
acb1ed1fd3
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -31,13 +32,12 @@ func (s *Server) GoogleCallbackHandlerV2(ctx *gin.Context) {
|
|||||||
domain := s.deps.EnvironmentConfig.FrontendDomain
|
domain := s.deps.EnvironmentConfig.FrontendDomain
|
||||||
|
|
||||||
if jwt, err := s.deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
if jwt, err := s.deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
||||||
redirectUrl := fmt.Sprintf("%s/v2/web/login?error=%s", domain, url.QueryEscape(err.Error()))
|
url := fmt.Sprintf("%s/v2/web/login?error=%s", domain, url.QueryEscape(err.Error()))
|
||||||
ctx.Redirect(http.StatusSeeOther, redirectUrl)
|
ctx.Redirect(http.StatusSeeOther, url)
|
||||||
} else {
|
} else {
|
||||||
// Pass JWT via query param - frontend will set the cookie
|
url := fmt.Sprintf("%s/v2/web/home", domain)
|
||||||
// This bypasses cross-origin cookie issues with Cloudflare/proxies
|
s.SetCookie(ctx, "jwt_token", jwt, time.Hour*24*7)
|
||||||
redirectUrl := fmt.Sprintf("%s/v2/web/auth/callback?token=%s", domain, url.QueryEscape(jwt))
|
ctx.Redirect(http.StatusSeeOther, url)
|
||||||
ctx.Redirect(http.StatusSeeOther, redirectUrl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import { use, type ReactNode } from 'react';
|
|||||||
import { AuthContext } from './context/AuthContext';
|
import { AuthContext } from './context/AuthContext';
|
||||||
import RecipePage from './pages/Recipe';
|
import RecipePage from './pages/Recipe';
|
||||||
import SearchPage from './pages/Search';
|
import SearchPage from './pages/Search';
|
||||||
import AuthCallback from './pages/AuthCallback';
|
|
||||||
|
|
||||||
function ProtectedRoute({ children }: { children: ReactNode }) {
|
function ProtectedRoute({ children }: { children: ReactNode }) {
|
||||||
const { isLoggedIn } = use(AuthContext)
|
const { isLoggedIn } = use(AuthContext)
|
||||||
@ -38,9 +37,6 @@ function App() {
|
|||||||
{/* Login page does not inherit WebLayout */}
|
{/* Login page does not inherit WebLayout */}
|
||||||
<Route path="/v2/web/login" element={<LoginPage />} />
|
<Route path="/v2/web/login" element={<LoginPage />} />
|
||||||
|
|
||||||
{/* Auth callback - handles token from OAuth redirect */}
|
|
||||||
<Route path="/v2/web/auth/callback" element={<AuthCallback />} />
|
|
||||||
|
|
||||||
<Route path="/v2/web" element={<WebLayout />}>
|
<Route path="/v2/web" element={<WebLayout />}>
|
||||||
<Route index element={<Navigate to={ROUTE_CONSTANTS.Home} replace />} />
|
<Route index element={<Navigate to={ROUTE_CONSTANTS.Home} replace />} />
|
||||||
<Route path="home" element={<Home />} />
|
<Route path="home" element={<Home />} />
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
import { useEffect } from "react";
|
|
||||||
import { useSearchParams, useNavigate } from "react-router-dom";
|
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
export default function AuthCallback() {
|
|
||||||
const [searchParams] = useSearchParams();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [, setCookie] = useCookies(["jwt_token"]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const token = searchParams.get("token");
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
// Set cookie with 7 day expiration, accessible across all subdomains
|
|
||||||
setCookie("jwt_token", token, {
|
|
||||||
path: "/",
|
|
||||||
maxAge: 60 * 60 * 24 * 7, // 7 days in seconds
|
|
||||||
secure: true,
|
|
||||||
sameSite: "lax",
|
|
||||||
});
|
|
||||||
void navigate("/v2/web/home", { replace: true });
|
|
||||||
} else {
|
|
||||||
// No token provided, redirect to login
|
|
||||||
void navigate("/v2/web/login", { replace: true });
|
|
||||||
}
|
|
||||||
}, [searchParams, setCookie, navigate]);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user