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
41 changes: 37 additions & 4 deletions frontend/src/routes/desktop-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect } from "react";
import { useOpenSecret } from "@opensecret/react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Loader2 } from "lucide-react";
import { AppleAuthProvider } from "@/components/AppleAuthProvider";

// Define the search parameters interface
interface DesktopAuthSearchParams {
Expand Down Expand Up @@ -44,17 +45,20 @@ function DesktopAuth() {
sessionStorage.setItem("selected_plan", selected_plan);
}

// Initiate appropriate OAuth flow
// For Apple, we don't need to do anything here - the AppleAuthProvider
// component will handle the authentication flow with popup
if (provider === "apple") {
return;
}

// Initiate appropriate OAuth flow for GitHub and Google
let auth_url;
if (provider === "github") {
const result = await os.initiateGitHubAuth("");
auth_url = result.auth_url;
} else if (provider === "google") {
const result = await os.initiateGoogleAuth("");
auth_url = result.auth_url;
} else if (provider === "apple") {
const result = await os.initiateAppleAuth("");
auth_url = result.auth_url;
} else {
throw new Error("Unsupported provider");
}
Expand All @@ -71,6 +75,35 @@ function DesktopAuth() {
initiateAuth();
}, [os, provider, selected_plan, navigate]);

// Special handling for Apple OAuth - use popup instead of redirect
if (provider === "apple") {
return (
<Card className="max-w-md mx-auto mt-20">
<CardHeader>
<CardTitle>Apple Sign In</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">Click the button below to sign in with Apple:</p>
<AppleAuthProvider
onError={(error) => {
console.error("Apple auth error:", error);
navigate({ to: "/login" });
}}
redirectAfterLogin={(plan) => {
if (plan) {
navigate({ to: "/pricing", search: { selected_plan: plan } });
} else {
navigate({ to: "/" });
}
}}
selectedPlan={selected_plan}
inviteCode=""
/>
</CardContent>
</Card>
);
}

return (
<Card className="max-w-md mx-auto mt-20">
<CardHeader>
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ function LoginPage() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [isIOS, setIsIOS] = useState(false);
const [isTauriEnv, setIsTauriEnv] = useState(false);

// Check if running on iOS
// Check if running on iOS and in Tauri environment
useEffect(() => {
const checkPlatform = async () => {
try {
// First check if we're in a Tauri environment
let isTauriEnv = false;
try {
isTauriEnv = await isTauri();
} catch {
// Not in Tauri environment
isTauriEnv = false;
}
let tauriEnv = false;
tauriEnv = await isTauri();

setIsTauriEnv(tauriEnv);

// Only check platform type if we're in a Tauri environment
if (isTauriEnv) {
if (tauriEnv) {
const platform = await type();
setIsIOS(platform === "ios");
} else {
Expand All @@ -65,6 +63,7 @@ function LoginPage() {
} catch (error) {
console.error("Error checking platform:", error);
setIsIOS(false);
setIsTauriEnv(false);
}
};

Expand Down Expand Up @@ -305,7 +304,7 @@ function LoginPage() {
<Google className="mr-2 h-4 w-4" />
Log in with Google
</Button>
{isIOS ? (
{isTauriEnv ? (
<Button onClick={handleAppleLogin} className="w-full">
<Apple className="mr-2 h-4 w-4" />
Log in with Apple
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ function SignupPage() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [isIOS, setIsIOS] = useState(false);
const [isTauriEnv, setIsTauriEnv] = useState(false);

// Check if running on iOS
// Check if running on iOS and in Tauri environment
useEffect(() => {
const checkPlatform = async () => {
try {
// First check if we're in a Tauri environment
let isTauriEnv = false;
try {
isTauriEnv = await isTauri();
} catch {
// Not in Tauri environment
isTauriEnv = false;
}
let tauriEnv = false;
tauriEnv = await isTauri();

setIsTauriEnv(tauriEnv);

// Only check platform type if we're in a Tauri environment
if (isTauriEnv) {
if (tauriEnv) {
const platform = await type();
setIsIOS(platform === "ios");
} else {
Expand All @@ -65,6 +63,7 @@ function SignupPage() {
} catch (error) {
console.error("Error checking platform:", error);
setIsIOS(false);
setIsTauriEnv(false);
}
};

Expand Down Expand Up @@ -305,7 +304,7 @@ function SignupPage() {
<Google className="mr-2 h-4 w-4" />
Sign up with Google
</Button>
{isIOS ? (
{isTauriEnv ? (
<Button onClick={handleAppleSignup} className="w-full">
<Apple className="mr-2 h-4 w-4" />
Sign up with Apple
Expand Down
Loading