mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
fix(web):update secondary auth entrypoints
This commit is contained in:
parent
1163557453
commit
54ff86dcc2
3 changed files with 22 additions and 11 deletions
|
|
@ -17,8 +17,7 @@ import { ShortcutKbd } from "@/components/ui/shortcut-kbd";
|
|||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useElectronAPI } from "@/hooks/use-platform";
|
||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||
import { setBearerToken } from "@/lib/auth-utils";
|
||||
import { buildBackendUrl } from "@/lib/env-config";
|
||||
import { setBearerToken, setRefreshToken } from "@/lib/auth-utils";
|
||||
|
||||
type ShortcutKey = "generalAssist" | "quickAsk" | "screenshotAssist";
|
||||
type ShortcutMap = typeof DEFAULT_SHORTCUTS;
|
||||
|
|
@ -237,10 +236,17 @@ export default function DesktopLoginPage() {
|
|||
[updateShortcut]
|
||||
);
|
||||
|
||||
const handleGoogleLogin = () => {
|
||||
const handleGoogleLogin = async () => {
|
||||
if (isGoogleRedirecting) return;
|
||||
setIsGoogleRedirecting(true);
|
||||
window.location.href = buildBackendUrl("/auth/google/authorize-redirect");
|
||||
try {
|
||||
await api?.startGoogleOAuth?.();
|
||||
await autoSetSearchSpace();
|
||||
router.push("/auth/callback");
|
||||
} catch (error) {
|
||||
setIsGoogleRedirecting(false);
|
||||
toast.error(error instanceof Error ? error.message : "Google sign-in failed");
|
||||
}
|
||||
};
|
||||
|
||||
const autoSetSearchSpace = async () => {
|
||||
|
|
@ -266,16 +272,20 @@ export default function DesktopLoginPage() {
|
|||
password,
|
||||
grant_type: "password",
|
||||
});
|
||||
const refreshToken = (data as { refresh_token?: string | null }).refresh_token;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
sessionStorage.setItem("login_success_tracked", "true");
|
||||
}
|
||||
|
||||
setBearerToken(data.access_token);
|
||||
if (refreshToken) {
|
||||
setRefreshToken(refreshToken);
|
||||
}
|
||||
await autoSetSearchSpace();
|
||||
|
||||
setTimeout(() => {
|
||||
router.push(`/auth/callback?token=${data.access_token}`);
|
||||
router.push("/auth/callback");
|
||||
}, 300);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@ import {
|
|||
} from "@/components/ui/card";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import type { AcceptInviteResponse } from "@/contracts/types/invites.types";
|
||||
import { useSession } from "@/hooks/use-session";
|
||||
import { invitesApiService } from "@/lib/apis/invites-api.service";
|
||||
import { getBearerToken, setRedirectPath } from "@/lib/auth-utils";
|
||||
import { setRedirectPath } from "@/lib/auth-utils";
|
||||
import {
|
||||
trackSearchSpaceInviteAccepted,
|
||||
trackSearchSpaceInviteDeclined,
|
||||
|
|
@ -43,6 +44,7 @@ export default function InviteAcceptPage() {
|
|||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const inviteCode = params.invite_code as string;
|
||||
const session = useSession();
|
||||
|
||||
const { data: inviteInfo = null, isLoading: loading } = useQuery({
|
||||
queryKey: cacheKeys.invites.info(inviteCode),
|
||||
|
|
@ -81,11 +83,9 @@ export default function InviteAcceptPage() {
|
|||
|
||||
// Check if user is logged in
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
const token = getBearerToken();
|
||||
setIsLoggedIn(!!token);
|
||||
}
|
||||
}, []);
|
||||
if (session.status === "loading") return;
|
||||
setIsLoggedIn(session.status === "authenticated");
|
||||
}, [session.status]);
|
||||
|
||||
const handleAccept = async () => {
|
||||
setAccepting(true);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export async function GET(request: NextRequest) {
|
|||
headers: {
|
||||
Authorization: request.headers.get("authorization") || "",
|
||||
"X-API-Key": request.headers.get("x-api-key") || "",
|
||||
Cookie: request.headers.get("cookie") || "",
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue