mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
93 lines
2.1 KiB
Handlebars
93 lines
2.1 KiB
Handlebars
import { authClient } from "@/lib/auth-client";
|
|
{{#if (eq api "trpc")}}
|
|
import { queryClient } from "@/utils/trpc";
|
|
{{/if}}
|
|
{{#if (eq api "orpc")}}
|
|
import { queryClient } from "@/utils/orpc";
|
|
{{/if}}
|
|
import { useState } from "react";
|
|
import {
|
|
ActivityIndicator,
|
|
Text,
|
|
TextInput,
|
|
TouchableOpacity,
|
|
View,
|
|
} from "react-native";
|
|
|
|
export function SignIn() {
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const handleLogin = async () => {
|
|
setIsLoading(true);
|
|
setError(null);
|
|
|
|
await authClient.signIn.email(
|
|
{
|
|
email,
|
|
password,
|
|
},
|
|
{
|
|
onError: (error) => {
|
|
setError(error.error?.message || "Failed to sign in");
|
|
setIsLoading(false);
|
|
},
|
|
onSuccess: () => {
|
|
setEmail("");
|
|
setPassword("");
|
|
queryClient.refetchQueries();
|
|
},
|
|
onFinished: () => {
|
|
setIsLoading(false);
|
|
},
|
|
},
|
|
);
|
|
};
|
|
|
|
return (
|
|
<View className="mt-6 p-4 bg-card rounded-lg border border-border">
|
|
<Text className="text-lg font-semibold text-foreground mb-4">
|
|
Sign In
|
|
</Text>
|
|
|
|
{error && (
|
|
<View className="mb-4 p-3 bg-destructive/10 rounded-md">
|
|
<Text className="text-destructive text-sm">{error}</Text>
|
|
</View>
|
|
)}
|
|
|
|
<TextInput
|
|
className="mb-3 p-4 rounded-md bg-input text-foreground border border-input"
|
|
placeholder="Email"
|
|
value={email}
|
|
onChangeText={setEmail}
|
|
placeholderTextColor="#9CA3AF"
|
|
keyboardType="email-address"
|
|
autoCapitalize="none"
|
|
/>
|
|
|
|
<TextInput
|
|
className="mb-4 p-4 rounded-md bg-input text-foreground border border-input"
|
|
placeholder="Password"
|
|
value={password}
|
|
onChangeText={setPassword}
|
|
placeholderTextColor="#9CA3AF"
|
|
secureTextEntry
|
|
/>
|
|
|
|
<TouchableOpacity
|
|
onPress={handleLogin}
|
|
disabled={isLoading}
|
|
className="bg-primary p-4 rounded-md flex-row justify-center items-center"
|
|
>
|
|
{isLoading ? (
|
|
<ActivityIndicator size="small" color="#fff" />
|
|
) : (
|
|
<Text className="text-primary-foreground font-medium">Sign In</Text>
|
|
)}
|
|
</TouchableOpacity>
|
|
</View>
|
|
);
|
|
} |