@highbeek/create-rnstarterkit 1.0.2-beta.2 → 1.0.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/create-rnstarterkit.js +6 -0
- package/dist/src/generators/appGenerator.js +3 -1
- package/dist/templates/cli-base/.bundle/config +2 -0
- package/dist/templates/cli-base/.eslintrc.js +4 -0
- package/dist/templates/cli-base/.prettierrc.js +5 -0
- package/dist/templates/cli-base/.watchmanconfig +1 -0
- package/dist/templates/cli-base/App.tsx +45 -0
- package/dist/templates/cli-base/Gemfile +16 -0
- package/dist/templates/cli-base/Gemfile.lock +169 -0
- package/dist/templates/cli-base/README.md +97 -0
- package/dist/templates/cli-base/__tests__/App.test.tsx +13 -0
- package/dist/templates/cli-base/android/app/build.gradle +119 -0
- package/dist/templates/cli-base/android/app/debug.keystore +0 -0
- package/dist/templates/cli-base/android/app/proguard-rules.pro +10 -0
- package/dist/templates/cli-base/android/app/src/main/AndroidManifest.xml +27 -0
- package/dist/templates/cli-base/android/app/src/main/java/com/baseapp/MainActivity.kt +22 -0
- package/dist/templates/cli-base/android/app/src/main/java/com/baseapp/MainApplication.kt +27 -0
- package/dist/templates/cli-base/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/dist/templates/cli-base/android/app/src/main/res/values/strings.xml +3 -0
- package/dist/templates/cli-base/android/app/src/main/res/values/styles.xml +9 -0
- package/dist/templates/cli-base/android/build.gradle +21 -0
- package/dist/templates/cli-base/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/dist/templates/cli-base/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/dist/templates/cli-base/android/gradle.properties +44 -0
- package/dist/templates/cli-base/android/gradlew +251 -0
- package/dist/templates/cli-base/android/gradlew.bat +99 -0
- package/dist/templates/cli-base/android/settings.gradle +6 -0
- package/dist/templates/cli-base/app.json +4 -0
- package/dist/templates/cli-base/babel.config.js +3 -0
- package/dist/templates/cli-base/index.js +9 -0
- package/dist/templates/cli-base/ios/.xcode.env +11 -0
- package/dist/templates/cli-base/ios/BaseApp/AppDelegate.swift +48 -0
- package/dist/templates/cli-base/ios/BaseApp/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/dist/templates/cli-base/ios/BaseApp/Images.xcassets/Contents.json +6 -0
- package/dist/templates/cli-base/ios/BaseApp/Info.plist +60 -0
- package/dist/templates/cli-base/ios/BaseApp/LaunchScreen.storyboard +47 -0
- package/dist/templates/cli-base/ios/BaseApp/PrivacyInfo.xcprivacy +37 -0
- package/dist/templates/cli-base/ios/BaseApp.xcodeproj/project.pbxproj +494 -0
- package/dist/templates/cli-base/ios/BaseApp.xcodeproj/xcshareddata/xcschemes/BaseApp.xcscheme +88 -0
- package/dist/templates/cli-base/ios/BaseApp.xcworkspace/contents.xcworkspacedata +10 -0
- package/dist/templates/cli-base/ios/Podfile +34 -0
- package/dist/templates/cli-base/ios/Podfile.lock +2165 -0
- package/dist/templates/cli-base/jest.config.js +3 -0
- package/dist/templates/cli-base/metro.config.js +11 -0
- package/dist/templates/cli-base/package-lock.json +11859 -0
- package/dist/templates/cli-base/package.json +41 -0
- package/dist/templates/cli-base/tsconfig.json +8 -0
- package/dist/templates/expo-base/.vscode/extensions.json +1 -0
- package/dist/templates/expo-base/.vscode/settings.json +7 -0
- package/dist/templates/expo-base/README.md +50 -0
- package/dist/templates/expo-base/app/(tabs)/_layout.tsx +35 -0
- package/dist/templates/expo-base/app/(tabs)/explore.tsx +112 -0
- package/dist/templates/expo-base/app/(tabs)/index.tsx +98 -0
- package/dist/templates/expo-base/app/_layout.tsx +24 -0
- package/dist/templates/expo-base/app/modal.tsx +29 -0
- package/dist/templates/expo-base/app.json +48 -0
- package/dist/templates/expo-base/assets/images/android-icon-background.png +0 -0
- package/dist/templates/expo-base/assets/images/android-icon-foreground.png +0 -0
- package/dist/templates/expo-base/assets/images/android-icon-monochrome.png +0 -0
- package/dist/templates/expo-base/assets/images/favicon.png +0 -0
- package/dist/templates/expo-base/assets/images/icon.png +0 -0
- package/dist/templates/expo-base/assets/images/partial-react-logo.png +0 -0
- package/dist/templates/expo-base/assets/images/react-logo.png +0 -0
- package/dist/templates/expo-base/assets/images/react-logo@2x.png +0 -0
- package/dist/templates/expo-base/assets/images/react-logo@3x.png +0 -0
- package/dist/templates/expo-base/assets/images/splash-icon.png +0 -0
- package/dist/templates/expo-base/components/external-link.tsx +25 -0
- package/dist/templates/expo-base/components/haptic-tab.tsx +18 -0
- package/dist/templates/expo-base/components/hello-wave.tsx +19 -0
- package/dist/templates/expo-base/components/parallax-scroll-view.tsx +79 -0
- package/dist/templates/expo-base/components/themed-text.tsx +60 -0
- package/dist/templates/expo-base/components/themed-view.tsx +14 -0
- package/dist/templates/expo-base/components/ui/collapsible.tsx +45 -0
- package/dist/templates/expo-base/components/ui/icon-symbol.ios.tsx +32 -0
- package/dist/templates/expo-base/components/ui/icon-symbol.tsx +41 -0
- package/dist/templates/expo-base/constants/theme.ts +53 -0
- package/dist/templates/expo-base/eslint.config.js +10 -0
- package/dist/templates/expo-base/hooks/use-color-scheme.ts +1 -0
- package/dist/templates/expo-base/hooks/use-color-scheme.web.ts +21 -0
- package/dist/templates/expo-base/hooks/use-theme-color.ts +21 -0
- package/dist/templates/expo-base/package-lock.json +12916 -0
- package/dist/templates/expo-base/package.json +47 -0
- package/dist/templates/expo-base/scripts/reset-project.js +112 -0
- package/dist/templates/expo-base/tsconfig.json +17 -0
- package/dist/templates/optional/apiClient/api/client.ts +86 -0
- package/dist/templates/optional/apiClient/api/index.ts +1 -0
- package/dist/templates/optional/apiClient/config/env.cli.ts +5 -0
- package/dist/templates/optional/apiClient/config/env.expo.ts +4 -0
- package/dist/templates/optional/apiClient/config/env.ts +1 -0
- package/dist/templates/optional/apiClient/env.d.ts +3 -0
- package/dist/templates/optional/auth-context/api/authApi.ts +14 -0
- package/dist/templates/optional/auth-context/context/AuthContext.tsx +47 -0
- package/dist/templates/optional/auth-context/navigation/ProtectedStack.tsx +38 -0
- package/dist/templates/optional/auth-context/navigation/cli/BottomTabs.tsx +17 -0
- package/dist/templates/optional/auth-context/navigation/expo/BottomTabs.tsx +29 -0
- package/dist/templates/optional/auth-context/screens/HomeScreen.tsx +14 -0
- package/dist/templates/optional/auth-context/screens/LoginScreen.tsx +28 -0
- package/dist/templates/optional/auth-context/screens/ProfileScreen.tsx +10 -0
- package/dist/templates/optional/auth-context/screens/RegisterScreen.tsx +28 -0
- package/dist/templates/optional/auth-context/screens/SettingsScreen.tsx +10 -0
- package/dist/templates/optional/auth-context/utils/storage.ts +13 -0
- package/dist/templates/optional/auth-redux/api/authApi.ts +14 -0
- package/dist/templates/optional/auth-redux/navigation/ProtectedStack.tsx +30 -0
- package/dist/templates/optional/auth-redux/navigation/cli/BottomTabs.tsx +17 -0
- package/dist/templates/optional/auth-redux/navigation/expo/BottomTabs.tsx +31 -0
- package/dist/templates/optional/auth-redux/screens/HomeScreen.tsx +15 -0
- package/dist/templates/optional/auth-redux/screens/LoginScreen.tsx +29 -0
- package/dist/templates/optional/auth-redux/screens/ProfileScreen.tsx +14 -0
- package/dist/templates/optional/auth-redux/screens/RegisterScreen.tsx +14 -0
- package/dist/templates/optional/auth-redux/screens/SettingsScreen.tsx +14 -0
- package/dist/templates/optional/auth-redux/store/authSlice.ts +25 -0
- package/dist/templates/optional/auth-redux/store/store.ts +11 -0
- package/dist/templates/optional/auth-zustand/api/authApi.ts +14 -0
- package/dist/templates/optional/auth-zustand/navigation/BottomTabs.tsx +1 -0
- package/dist/templates/optional/auth-zustand/navigation/ProtectedStack.tsx +44 -0
- package/dist/templates/optional/auth-zustand/navigation/cli/BottomTabs.tsx +17 -0
- package/dist/templates/optional/auth-zustand/navigation/expo/BottomTabs.tsx +31 -0
- package/dist/templates/optional/auth-zustand/screens/HomeScreen.tsx +14 -0
- package/dist/templates/optional/auth-zustand/screens/LoginScreen.tsx +28 -0
- package/dist/templates/optional/auth-zustand/screens/ProfileScreen.tsx +10 -0
- package/dist/templates/optional/auth-zustand/screens/RegisterScreen.tsx +28 -0
- package/dist/templates/optional/auth-zustand/screens/SettingsScreen.tsx +10 -0
- package/dist/templates/optional/auth-zustand/store/authStore.ts +30 -0
- package/dist/templates/optional/auth-zustand/utils/storage.ts +13 -0
- package/package.json +2 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { View, TextInput, Button } from "react-native";
|
|
3
|
+
import { useDispatch } from "react-redux";
|
|
4
|
+
import { login } from "../store/authSlice";
|
|
5
|
+
import { loginApi } from "../api/authApi";
|
|
6
|
+
|
|
7
|
+
export default function LoginScreen() {
|
|
8
|
+
const dispatch = useDispatch();
|
|
9
|
+
const [email, setEmail] = useState("");
|
|
10
|
+
const [password, setPassword] = useState("");
|
|
11
|
+
|
|
12
|
+
const handleLogin = async () => {
|
|
13
|
+
const token = await loginApi(email, password);
|
|
14
|
+
dispatch(login(token));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<View>
|
|
19
|
+
<TextInput placeholder="Email" value={email} onChangeText={setEmail} />
|
|
20
|
+
<TextInput
|
|
21
|
+
placeholder="Password"
|
|
22
|
+
value={password}
|
|
23
|
+
onChangeText={setPassword}
|
|
24
|
+
secureTextEntry
|
|
25
|
+
/>
|
|
26
|
+
<Button title="Login" onPress={handleLogin} />
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
const ProfileScreen = () => {
|
|
5
|
+
return (
|
|
6
|
+
<View>
|
|
7
|
+
<Text>ProfileScreen</Text>
|
|
8
|
+
</View>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default ProfileScreen
|
|
13
|
+
|
|
14
|
+
const styles = StyleSheet.create({})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
const RegisterScreen = () => {
|
|
5
|
+
return (
|
|
6
|
+
<View>
|
|
7
|
+
<Text>RegisterScreen</Text>
|
|
8
|
+
</View>
|
|
9
|
+
);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default RegisterScreen;
|
|
13
|
+
|
|
14
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
const SettingsScreen = () => {
|
|
5
|
+
return (
|
|
6
|
+
<View>
|
|
7
|
+
<Text>SettingsScreen</Text>
|
|
8
|
+
</View>
|
|
9
|
+
);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default SettingsScreen;
|
|
13
|
+
|
|
14
|
+
const styles = StyleSheet.create({});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
2
|
+
|
|
3
|
+
interface AuthState {
|
|
4
|
+
token: string | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const initialState: AuthState = {
|
|
8
|
+
token: null,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const authSlice = createSlice({
|
|
12
|
+
name: "auth",
|
|
13
|
+
initialState,
|
|
14
|
+
reducers: {
|
|
15
|
+
login(state, action: PayloadAction<string>) {
|
|
16
|
+
state.token = action.payload;
|
|
17
|
+
},
|
|
18
|
+
logout(state) {
|
|
19
|
+
state.token = null;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const { login, logout } = authSlice.actions;
|
|
25
|
+
export default authSlice.reducer;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { configureStore } from "@reduxjs/toolkit";
|
|
2
|
+
import authReducer from "./authSlice";
|
|
3
|
+
|
|
4
|
+
export const store = configureStore({
|
|
5
|
+
reducer: {
|
|
6
|
+
auth: authReducer,
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export type RootState = ReturnType<typeof store.getState>;
|
|
11
|
+
export type AppDispatch = typeof store.dispatch;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function assertCredentials(email: string, password: string) {
|
|
2
|
+
if (!email.trim()) throw new Error("Email is required");
|
|
3
|
+
if (!password.trim()) throw new Error("Password is required");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const loginApi = async (email: string, password: string) => {
|
|
7
|
+
assertCredentials(email, password);
|
|
8
|
+
return `demo-token-${email.trim().toLowerCase()}`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const registerApi = async (email: string, password: string) => {
|
|
12
|
+
assertCredentials(email, password);
|
|
13
|
+
return `demo-token-${email.trim().toLowerCase()}`;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./cli/BottomTabs";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { ActivityIndicator, View } from "react-native";
|
|
3
|
+
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
|
4
|
+
import LoginScreen from "../screens/LoginScreen";
|
|
5
|
+
import RegisterScreen from "../screens/RegisterScreen";
|
|
6
|
+
import BottomTabs from "./BottomTabs";
|
|
7
|
+
import { useAuthStore } from "../store/authStore";
|
|
8
|
+
|
|
9
|
+
const Stack = createNativeStackNavigator();
|
|
10
|
+
|
|
11
|
+
export default function ProtectedStack() {
|
|
12
|
+
const token = useAuthStore((state) => state.token);
|
|
13
|
+
const isHydrated = useAuthStore((state) => state.isHydrated);
|
|
14
|
+
const hydrate = useAuthStore((state) => state.hydrate);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
void hydrate();
|
|
18
|
+
}, [hydrate]);
|
|
19
|
+
|
|
20
|
+
if (!isHydrated) {
|
|
21
|
+
return (
|
|
22
|
+
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
|
|
23
|
+
<ActivityIndicator />
|
|
24
|
+
</View>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Stack.Navigator>
|
|
30
|
+
{token ? (
|
|
31
|
+
<Stack.Screen
|
|
32
|
+
name="Main"
|
|
33
|
+
component={BottomTabs}
|
|
34
|
+
options={{ headerShown: false }}
|
|
35
|
+
/>
|
|
36
|
+
) : (
|
|
37
|
+
<>
|
|
38
|
+
<Stack.Screen name="Login" component={LoginScreen} />
|
|
39
|
+
<Stack.Screen name="Register" component={RegisterScreen} />
|
|
40
|
+
</>
|
|
41
|
+
)}
|
|
42
|
+
</Stack.Navigator>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
|
|
3
|
+
import HomeScreen from "../../screens/HomeScreen";
|
|
4
|
+
import ProfileScreen from "../../screens/ProfileScreen";
|
|
5
|
+
import SettingsScreen from "../../screens/SettingsScreen";
|
|
6
|
+
|
|
7
|
+
const Tab = createBottomTabNavigator();
|
|
8
|
+
|
|
9
|
+
export default function BottomTabs() {
|
|
10
|
+
return (
|
|
11
|
+
<Tab.Navigator screenOptions={{ headerShown: false }}>
|
|
12
|
+
<Tab.Screen name="Home" component={HomeScreen} />
|
|
13
|
+
<Tab.Screen name="Profile" component={ProfileScreen} />
|
|
14
|
+
<Tab.Screen name="Settings" component={SettingsScreen} />
|
|
15
|
+
</Tab.Navigator>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
|
|
3
|
+
import { Ionicons } from "@expo/vector-icons";
|
|
4
|
+
import HomeScreen from "../../screens/HomeScreen";
|
|
5
|
+
import ProfileScreen from "../../screens/ProfileScreen";
|
|
6
|
+
import SettingsScreen from "../../screens/SettingsScreen";
|
|
7
|
+
|
|
8
|
+
const Tab = createBottomTabNavigator();
|
|
9
|
+
|
|
10
|
+
export default function BottomTabs() {
|
|
11
|
+
return (
|
|
12
|
+
<Tab.Navigator
|
|
13
|
+
screenOptions={({ route }) => ({
|
|
14
|
+
headerShown: false,
|
|
15
|
+
tabBarIcon: ({ color, size }) => {
|
|
16
|
+
let iconName: string = "home";
|
|
17
|
+
|
|
18
|
+
if (route.name === "Home") iconName = "home";
|
|
19
|
+
else if (route.name === "Profile") iconName = "person";
|
|
20
|
+
else if (route.name === "Settings") iconName = "settings";
|
|
21
|
+
|
|
22
|
+
return <Ionicons name={iconName as any} size={size} color={color} />;
|
|
23
|
+
},
|
|
24
|
+
})}
|
|
25
|
+
>
|
|
26
|
+
<Tab.Screen name="Home" component={HomeScreen} />
|
|
27
|
+
<Tab.Screen name="Profile" component={ProfileScreen} />
|
|
28
|
+
<Tab.Screen name="Settings" component={SettingsScreen} />
|
|
29
|
+
</Tab.Navigator>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, Text, Button } from "react-native";
|
|
3
|
+
import { useAuthStore } from "../store/authStore";
|
|
4
|
+
|
|
5
|
+
export default function HomeScreen() {
|
|
6
|
+
const logout = useAuthStore((state) => state.logout);
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<View style={{ padding: 20 }}>
|
|
10
|
+
<Text>Welcome Home!</Text>
|
|
11
|
+
<Button title="Logout" onPress={() => void logout()} />
|
|
12
|
+
</View>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { View, TextInput, Button } from "react-native";
|
|
3
|
+
import { loginApi } from "../api/authApi";
|
|
4
|
+
import { useAuthStore } from "../store/authStore";
|
|
5
|
+
|
|
6
|
+
export default function LoginScreen() {
|
|
7
|
+
const login = useAuthStore((state) => state.login);
|
|
8
|
+
const [email, setEmail] = useState("");
|
|
9
|
+
const [password, setPassword] = useState("");
|
|
10
|
+
|
|
11
|
+
const handleLogin = async () => {
|
|
12
|
+
const token = await loginApi(email, password);
|
|
13
|
+
await login(token);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<View style={{ padding: 20 }}>
|
|
18
|
+
<TextInput placeholder="Email" value={email} onChangeText={setEmail} />
|
|
19
|
+
<TextInput
|
|
20
|
+
placeholder="Password"
|
|
21
|
+
value={password}
|
|
22
|
+
onChangeText={setPassword}
|
|
23
|
+
secureTextEntry
|
|
24
|
+
/>
|
|
25
|
+
<Button title="Login" onPress={() => void handleLogin()} />
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { View, TextInput, Button } from "react-native";
|
|
3
|
+
import { registerApi } from "../api/authApi";
|
|
4
|
+
import { useAuthStore } from "../store/authStore";
|
|
5
|
+
|
|
6
|
+
export default function RegisterScreen() {
|
|
7
|
+
const login = useAuthStore((state) => state.login);
|
|
8
|
+
const [email, setEmail] = useState("");
|
|
9
|
+
const [password, setPassword] = useState("");
|
|
10
|
+
|
|
11
|
+
const handleRegister = async () => {
|
|
12
|
+
const token = await registerApi(email, password);
|
|
13
|
+
await login(token);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<View style={{ padding: 20 }}>
|
|
18
|
+
<TextInput placeholder="Email" value={email} onChangeText={setEmail} />
|
|
19
|
+
<TextInput
|
|
20
|
+
placeholder="Password"
|
|
21
|
+
value={password}
|
|
22
|
+
onChangeText={setPassword}
|
|
23
|
+
secureTextEntry
|
|
24
|
+
/>
|
|
25
|
+
<Button title="Register" onPress={() => void handleRegister()} />
|
|
26
|
+
</View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { getToken, removeToken, storeToken } from "../utils/storage";
|
|
3
|
+
|
|
4
|
+
type AuthState = {
|
|
5
|
+
token: string | null;
|
|
6
|
+
isHydrated: boolean;
|
|
7
|
+
hydrate: () => Promise<void>;
|
|
8
|
+
login: (token: string) => Promise<void>;
|
|
9
|
+
logout: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useAuthStore = create<AuthState>((set) => ({
|
|
13
|
+
token: null,
|
|
14
|
+
isHydrated: false,
|
|
15
|
+
|
|
16
|
+
hydrate: async () => {
|
|
17
|
+
const token = await getToken();
|
|
18
|
+
set({ token, isHydrated: true });
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
login: async (token: string) => {
|
|
22
|
+
await storeToken(token);
|
|
23
|
+
set({ token });
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
logout: async () => {
|
|
27
|
+
await removeToken();
|
|
28
|
+
set({ token: null });
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
|
|
3
|
+
export const storeToken = async (token: string) => {
|
|
4
|
+
await AsyncStorage.setItem("@token", token);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const getToken = async () => {
|
|
8
|
+
return await AsyncStorage.getItem("@token");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const removeToken = async () => {
|
|
12
|
+
await AsyncStorage.removeItem("@token");
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highbeek/create-rnstarterkit",
|
|
3
|
-
"version": "1.0.2-beta.
|
|
3
|
+
"version": "1.0.2-beta.3",
|
|
4
4
|
"description": "CLI to scaffold production-ready React Native app structures.",
|
|
5
5
|
"main": "dist/src/generators/appGenerator.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "tsc -p tsconfig.build.json",
|
|
14
|
+
"build": "tsc -p tsconfig.build.json && node scripts/copy-templates.js",
|
|
15
15
|
"prepublishOnly": "npm run build",
|
|
16
16
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
17
|
},
|