Skip to content

Commit 6602cf3

Browse files
committed
Still working on reworking backend
1 parent 2c403b5 commit 6602cf3

File tree

797 files changed

+271720
-802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

797 files changed

+271720
-802
lines changed

.env

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ FRONTEND_HOST=http://localhost:5173
1313
# Environment: local, staging, production
1414
ENVIRONMENT=local
1515

16-
PROJECT_NAME="Full Stack FastAPI Project"
17-
STACK_NAME=full-stack-fastapi-project
16+
PROJECT_NAME="Kondition Fastapi"
17+
STACK_NAME=kondition-fastapi
1818

1919
# Backend
2020
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://localhost.tiangolo.com"
21-
SECRET_KEY=changethis
21+
SECRET_KEY=S8T75_i6lcsZerDMe59A9tmyx0-AtFAzGY5bez_dsBw
2222
FIRST_SUPERUSER=[email protected]
23-
FIRST_SUPERUSER_PASSWORD=changethis
23+
FIRST_SUPERUSER_PASSWORD=VSOhm4DWGG8h1kOBAhlZYM0HqqL--r4CuAhZ-eXQX8Q
2424

2525
# Emails
2626
SMTP_HOST=
@@ -34,9 +34,9 @@ SMTP_PORT=587
3434
# Postgres
3535
POSTGRES_SERVER=localhost
3636
POSTGRES_PORT=5432
37-
POSTGRES_DB=app
37+
POSTGRES_DB=konditionDB
3838
POSTGRES_USER=postgres
39-
POSTGRES_PASSWORD=changethis
39+
POSTGRES_PASSWORD=d0pFlN6jcym0Fui_lc4dShkzzRAYUL78ToQTMoALE1g
4040

4141
SENTRY_DSN=
4242

KonditionExpo/app/(tabs)/_layout.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import { Tabs } from 'expo-router';
2-
import React from 'react';
1+
// app/(tabs)/_layout.tsx
2+
import { Tabs, Redirect } from 'expo-router';
3+
import { useEffect } from 'react';
4+
import { ActivityIndicator, View } from 'react-native';
35
import { Platform } from 'react-native';
46

7+
import { useAuth } from '@/contexts/AuthContext';
8+
import { Colors } from '@/constants/Colors';
9+
import { useColorScheme } from '@/hooks/useColorScheme';
510
import { HapticTab } from '@/components/HapticTab';
611
import { IconSymbol } from '@/components/ui/IconSymbol';
712
import TabBarBackground from '@/components/ui/TabBarBackground';
8-
import { Colors } from '@/constants/Colors';
9-
import { useColorScheme } from '@/hooks/useColorScheme';
1013

1114
export default function TabLayout() {
15+
const { token, loading } = useAuth();
1216
const colorScheme = useColorScheme();
1317

18+
if (loading) {
19+
return (
20+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
21+
<ActivityIndicator size="large" />
22+
</View>
23+
);
24+
}
25+
26+
if (!token) {
27+
return <Redirect href="/login" />;
28+
}
29+
1430
return (
1531
<Tabs
1632
screenOptions={{
@@ -20,7 +36,6 @@ export default function TabLayout() {
2036
tabBarBackground: TabBarBackground,
2137
tabBarStyle: Platform.select({
2238
ios: {
23-
// Use a transparent background on iOS to show the blur effect
2439
position: 'absolute',
2540
},
2641
default: {},

KonditionExpo/app/home.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { SafeAreaView, View, Text, StyleSheet, ScrollView, TouchableOpacity, Ima
44
import { LineChart, PieChart } from 'react-native-chart-kit';
55
import { router } from 'expo-router';
66
import { usePersonalBests } from "@/hooks/usePersonalBests";
7+
import { getAccessToken } from '@/scripts/auth';
8+
import { useEffect } from 'react';
9+
10+
711

812
const { width } = Dimensions.get('window');
913
//console.log(" 1 HomeScreen about to be rendered rendered");
@@ -17,6 +21,30 @@ const HomeScreen = () => {
1721
return null;
1822
}
1923
const { name } = user;
24+
useEffect(() => {
25+
const fetchAdminDbStructure = async () => {
26+
try {
27+
const token = await getAccessToken();
28+
const res = await fetch('http://localhost:8000/api/v1/inspect-db', {
29+
headers: {
30+
Authorization: `Bearer ${token}`,
31+
},
32+
});
33+
34+
if (!res.ok) {
35+
console.error(`Failed to fetch admin DB structure: ${res.status}`);
36+
return;
37+
}
38+
39+
const dbStructure = await res.json();
40+
console.log("🛠 Admin DB Structure:", dbStructure);
41+
} catch (err) {
42+
console.error("Error fetching admin DB structure:", err);
43+
}
44+
};
45+
46+
fetchAdminDbStructure();
47+
}, []);
2048
const heartRateData = [60, 62, 65, 70, 75, 78, 80, 82, 79, 76];
2149
const waterIntake = '4L';
2250
const sleepHours = '8h 20m';
@@ -29,7 +57,7 @@ const HomeScreen = () => {
2957
{ id: '2', type: 'Lowerbody Workout', calories: 200, duration: '30 minutes', icon: require('../assets/images/lowerbody.png') },
3058
// ... more workouts
3159
];
32-
const { pbs, loading } = usePersonalBests();
60+
const { pbs = [], loading } = usePersonalBests();
3361
const testPbs = pbs.length === 0 ? [{ metric: "Deadlift", value: 315, date: "2025-05-27" }] : pbs;
3462

3563
console.log('PBS LOADED:', pbs);
@@ -224,7 +252,7 @@ const HomeScreen = () => {
224252
) : pbs.length === 0 ? (
225253
<Text style={{ textAlign: 'center', color: '#999', marginBottom: 12 }}>No personal bests yet. Start training to set new records!</Text>
226254
) : (
227-
testPbs.map((pb) => (
255+
pbs.map((pb) => (
228256
<View key={pb.metric} style={styles.workoutItem}>
229257
<Image source={require('../assets/images/trophy.png')} style={styles.workoutIcon} />
230258
<View style={styles.workoutInfo}>

KonditionExpo/app/login.tsx

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Input } from '../components/ui/Input';
66
import { Checkbox } from '../components/ui/Checkbox';
77
import { router } from 'expo-router';
88
import { useUser } from '@/contexts/UserContext';
9+
import { useAuth } from '@/contexts/AuthContext';
10+
import { API_URL } from '@/constants/config';
911

1012
export default function LoginScreen() {
1113
const { setName: setUserName } = useUser();
@@ -15,39 +17,28 @@ export default function LoginScreen() {
1517
const [showPassword, setShowPassword] = useState(false);
1618
const [isLoading, setIsLoading] = useState(false);
1719
const [errors, setErrors] = useState<{ email?: string; password?: string }>({});
20+
const { login } = useAuth();
21+
1822

1923
const backgroundColor = useThemeColor({}, 'background');
2024
const textColor = useThemeColor({}, 'text');
2125
const tintColor = useThemeColor({}, 'tint');
2226

2327
const handleLogin = async () => {
24-
setErrors({});
25-
26-
const newErrors: { email?: string; password?: string } = {};
27-
28-
if (!email) newErrors.email = 'Email is required';
29-
else if (!/\S+@\S+\.\S+/.test(email)) newErrors.email = 'Please enter a valid email';
30-
31-
if (!password) newErrors.password = 'Password is required';
32-
else if (password.length < 6) newErrors.password = 'Password must be at least 6 characters';
33-
34-
if (Object.keys(newErrors).length > 0) {
35-
setErrors(newErrors);
36-
return;
37-
}
38-
39-
setIsLoading(true);
40-
4128
try {
42-
// Simulate API call
43-
await new Promise(resolve => setTimeout(resolve, 1500));
44-
45-
// Set the name (this mimics what signup does)
46-
setUserName('Returning User'); // You can replace this with a real name from API later
47-
48-
router.replace('/(tabs)');
49-
} catch (error) {
50-
console.error('Login error:', error);
29+
setIsLoading(true);
30+
await login(email, password); // Use context login logic
31+
setUserName(email); // optionally call setUserName if it's useful
32+
router.replace('/'); // Redirect to home or dashboard
33+
} catch (err: any) {
34+
console.error('Login error:', err instanceof Error ? err.message : err);
35+
if (err instanceof Error) {
36+
console.error('Login error:', err.message);
37+
console.error('Full stack:', err.stack);
38+
} else {
39+
console.error('Login error (raw):', err);
40+
}
41+
alert(`Login failed: ${err.message}`);
5142
} finally {
5243
setIsLoading(false);
5344
}

KonditionExpo/app/signup.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { Input } from '@/components/ui/Input';
44
import { Button } from '@/components/ui/Button';
55
import { router } from 'expo-router';
66
import { useUser } from '@/contexts/UserContext';
7+
import AsyncStorage from '@react-native-async-storage/async-storage';
8+
import { API_URL } from "@/constants/config";
9+
710

811

912

@@ -15,16 +18,45 @@ export default function SignUpScreen() {
1518
const [confirmPassword, setConfirmPassword] = useState('');
1619
const { setName: setUserName } = useUser();
1720

18-
const handleCreateAccount = () => {
21+
const handleCreateAccount = async () => {
1922
if (password !== confirmPassword) {
2023
alert("Passwords don't match");
2124
return;
2225
}
2326

24-
setUserName(name);
25-
26-
// TODO: Send signup data to API
27-
router.replace('/signup2');
27+
try {
28+
const res = await fetch(`http://localhost:8000/api/v1/register`, {
29+
method: "POST",
30+
headers: { "Content-Type": "application/json" },
31+
body: JSON.stringify({ email, password, name }),
32+
});
33+
console.log("response from signup: ", res);
34+
if (!res.ok) {
35+
const errData = await res.json().catch(() => ({}));
36+
console.log("ERROR DATA: ", errData);
37+
const errMsg =
38+
errData.detail || JSON.stringify(errData) || res.statusText || "Unknown error";
39+
alert("Signup failed: " + errMsg);
40+
return;
41+
}
42+
const data = await res.json();
43+
console.log("JSON DATA OF SIGNUP: ", data)
44+
if (res.ok) {
45+
// Optionally, auto-login after signup
46+
if (data.access_token) {
47+
await AsyncStorage.setItem("access_token", data.access_token);
48+
} else {
49+
console.warn("No token returned from signup");
50+
}
51+
setUserName(name);
52+
router.replace('/signup2');
53+
} else {
54+
alert(data.detail || "Signup failed");
55+
}
56+
} catch (err) {
57+
console.error("Signup error", err);
58+
alert("Something went wrong during signup.");
59+
}
2860
};
2961

3062

0 commit comments

Comments
 (0)