feat(mobile): magic-link login screen
This commit is contained in:
+127
-25
@@ -1,29 +1,105 @@
|
|||||||
import * as Application from 'expo-application';
|
import { auth } from '@chat-app/shared';
|
||||||
import { Link } from 'expo-router';
|
import { Redirect } from 'expo-router';
|
||||||
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
TextInput,
|
||||||
|
View,
|
||||||
|
} from 'react-native';
|
||||||
|
|
||||||
// Phase 0 landing screen. Just enough to prove the app boots and routes:
|
import { useAuth } from '../lib/authContext';
|
||||||
// * Netralax brand wordmark (replaces the previous "ChatApp" string).
|
import { env } from '../lib/env';
|
||||||
// * Runtime version from expo-application so we can spot stale builds
|
import { supabase } from '../lib/supabase';
|
||||||
// on a TestFlight tester's device at a glance.
|
import { colors } from '../theme/colors';
|
||||||
// * Placeholder nav link into (app)/chats — exercises Expo Router so a
|
|
||||||
// routing regression shows up here instead of mid-Phase-1.
|
// Phase 1 landing — magic-link login. Signup with invite code is not
|
||||||
//
|
// part of this MVP (accounts come from desktop / admin). After a
|
||||||
// Phase 1 replaces this with the actual magic-link login form.
|
// successful request the user sees a "Check your inbox" state until
|
||||||
|
// they tap the email link and Expo Router routes the deep link to
|
||||||
|
// app/auth/callback.tsx.
|
||||||
export default function Landing() {
|
export default function Landing() {
|
||||||
const version = Application.nativeApplicationVersion ?? '0.0.0';
|
const { session, loading } = useAuth();
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [sent, setSent] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
if (loading) return null;
|
||||||
|
if (session) return <Redirect href="/(app)/chats" />;
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
if (!email.includes('@')) {
|
||||||
|
setError('Bitte gültige E-Mail eingeben');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSubmitting(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
await auth.loginWithMagicLink(supabase, email.trim(), env.authRedirectUrl);
|
||||||
|
setSent(true);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Login fehlgeschlagen');
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent) {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.title}>Netralax</Text>
|
||||||
|
<Text style={styles.subtitle}>Check deine Mails</Text>
|
||||||
|
<Text style={styles.help}>
|
||||||
|
Wir haben dir einen Anmelde-Link an {email} geschickt. Tipp auf den Link, um
|
||||||
|
dich anzumelden.
|
||||||
|
</Text>
|
||||||
|
<Pressable
|
||||||
|
style={[styles.button, styles.buttonGhost]}
|
||||||
|
onPress={() => {
|
||||||
|
setSent(false);
|
||||||
|
setEmail('');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={styles.buttonText}>Andere E-Mail verwenden</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.title}>Netralax</Text>
|
<Text style={styles.title}>Netralax</Text>
|
||||||
<Text style={styles.subtitle}>Phase 0 — Deployment-Fundament</Text>
|
<Text style={styles.subtitle}>Mit Magic-Link anmelden</Text>
|
||||||
<Text style={styles.version}>v{version}</Text>
|
|
||||||
|
|
||||||
<Link href="/(app)/chats" asChild>
|
<TextInput
|
||||||
<Pressable style={styles.button}>
|
value={email}
|
||||||
<Text style={styles.buttonText}>Weiter (Smoke-Test)</Text>
|
onChangeText={setEmail}
|
||||||
</Pressable>
|
placeholder="du@beispiel.de"
|
||||||
</Link>
|
placeholderTextColor={colors.textDim}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
keyboardType="email-address"
|
||||||
|
textContentType="emailAddress"
|
||||||
|
style={styles.input}
|
||||||
|
editable={!submitting}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{error && <Text style={styles.error}>{error}</Text>}
|
||||||
|
|
||||||
|
<Pressable
|
||||||
|
style={[styles.button, submitting && styles.buttonDisabled]}
|
||||||
|
onPress={handleSubmit}
|
||||||
|
disabled={submitting}
|
||||||
|
>
|
||||||
|
{submitting ? (
|
||||||
|
<ActivityIndicator color={colors.text} />
|
||||||
|
) : (
|
||||||
|
<Text style={styles.buttonText}>Magic Link senden</Text>
|
||||||
|
)}
|
||||||
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -33,17 +109,43 @@ const styles = StyleSheet.create({
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
backgroundColor: '#0b0b0f',
|
backgroundColor: colors.bg,
|
||||||
padding: 24,
|
padding: 24,
|
||||||
},
|
},
|
||||||
title: { color: '#fff', fontSize: 32, fontWeight: '700', letterSpacing: 1 },
|
title: { color: colors.text, fontSize: 32, fontWeight: '700', letterSpacing: 1, marginBottom: 8 },
|
||||||
subtitle: { color: '#9ca3af', marginTop: 8, marginBottom: 4 },
|
subtitle: { color: colors.textMuted, fontSize: 14, marginBottom: 24 },
|
||||||
version: { color: '#6b7280', fontSize: 12, marginBottom: 32 },
|
help: {
|
||||||
|
color: colors.textMuted,
|
||||||
|
fontSize: 14,
|
||||||
|
textAlign: 'center',
|
||||||
|
marginHorizontal: 16,
|
||||||
|
marginBottom: 24,
|
||||||
|
lineHeight: 20,
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
width: '100%',
|
||||||
|
maxWidth: 360,
|
||||||
|
backgroundColor: colors.surface,
|
||||||
|
borderColor: colors.border,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderRadius: 12,
|
||||||
|
color: colors.text,
|
||||||
|
paddingHorizontal: 16,
|
||||||
|
paddingVertical: 14,
|
||||||
|
fontSize: 15,
|
||||||
|
marginBottom: 12,
|
||||||
|
},
|
||||||
|
error: { color: colors.danger, fontSize: 13, marginBottom: 12 },
|
||||||
button: {
|
button: {
|
||||||
backgroundColor: '#5865f2',
|
width: '100%',
|
||||||
|
maxWidth: 360,
|
||||||
|
backgroundColor: colors.accent,
|
||||||
paddingHorizontal: 24,
|
paddingHorizontal: 24,
|
||||||
paddingVertical: 14,
|
paddingVertical: 14,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
buttonText: { color: '#fff', fontWeight: '600', fontSize: 15 },
|
buttonGhost: { backgroundColor: 'transparent', borderWidth: 1, borderColor: colors.border },
|
||||||
|
buttonDisabled: { opacity: 0.6 },
|
||||||
|
buttonText: { color: colors.text, fontWeight: '600', fontSize: 15 },
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user