diff --git a/app/_layout.tsx b/app/_layout.tsx
index 4e00346..51bdd8b 100644
--- a/app/_layout.tsx
+++ b/app/_layout.tsx
@@ -8,9 +8,9 @@ export default function RootLayout() {
return (
<>
+
- {/*
- */}
+
>
diff --git a/screens/Authentication/LoginView.tsx b/screens/Authentication/LoginView.tsx
index 81cef56..1f397c2 100644
--- a/screens/Authentication/LoginView.tsx
+++ b/screens/Authentication/LoginView.tsx
@@ -2,7 +2,8 @@ import ButtonCustom from "@/components/Button/ButtonCustom";
import Spacing from "@/components/_ShareComponent/Spacing";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
import { MainColor } from "@/constants/color-palet";
-import { apiLogin, apiVersion } from "@/service/api";
+import { useAuth } from "@/hook/use-auth";
+import { apiVersion } from "@/service/api";
import { GStyles } from "@/styles/global-styles";
import { router } from "expo-router";
import { useEffect, useState } from "react";
@@ -16,12 +17,15 @@ export default function LoginView() {
const [inputValue, setInputValue] = useState("");
const [loading, setLoading] = useState(false);
+ const { loginWithNomor } = useAuth();
+
useEffect(() => {
onLoadVersion();
}, []);
async function onLoadVersion() {
const res = await apiVersion();
+ console.log("Version", res.data);
setVersion(res.data);
}
@@ -66,24 +70,26 @@ export default function LoginView() {
const fixNumber = inputValue.replace(/\s+/g, "");
const realNumber = callingCode + fixNumber;
- setLoading(true);
- const response = await apiLogin({ nomor: realNumber });
+ try {
+ setLoading(true);
+ // const response = await apiLogin({ nomor: realNumber });
+ await loginWithNomor(realNumber);
- if (response.success) {
Toast.show({
type: "success",
text1: "Sukses",
text2: "Kode OTP berhasil dikirim",
});
- router.navigate(`/verification?kodeId=${response.kodeId}`);
- setLoading(false);
- // router.replace("/(application)/coba");
- } else {
+
+ router.navigate(`/verification?nomor=${realNumber}`);
+ } catch (error) {
+ console.log("Error login", error);
Toast.show({
type: "error",
text1: "Error",
- text2: response.message,
+ text2: error as string,
});
+ } finally {
setLoading(false);
}
}
diff --git a/service/api.ts b/service/api.ts
index ac61460..b953f9a 100644
--- a/service/api.ts
+++ b/service/api.ts
@@ -1,3 +1,4 @@
+import AsyncStorage from "@react-native-async-storage/async-storage";
import axios, { AxiosInstance } from "axios";
import Constants from "expo-constants";
const API_BASE_URL = Constants.expoConfig?.extra?.API_BASE_URL;
@@ -12,9 +13,18 @@ export const apiClient: AxiosInstance = axios.create({
},
});
+// Endpoint yang TIDAK butuh token
+const PUBLIC_ROUTES = [
+ // "/version",
+ "/auth/send-otp",
+ "/auth/verify-otp",
+ "/auth/register",
+ "/auth/logout", // opsional, tergantung kebutuhan
+];
+
// apiClient.interceptors.request.use(
// (config) => {
-// const token = localStorage.getItem("token");
+// const token = AsyncStorage.getItem("authToken");
// if (token) {
// config.headers.Authorization = `Bearer ${token}`;
// }
@@ -25,6 +35,30 @@ export const apiClient: AxiosInstance = axios.create({
// }
// );
+apiClient.interceptors.request.use(
+ (config) => {
+ const token = AsyncStorage.getItem("authToken");
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`;
+ }
+
+ // const isPublic = PUBLIC_ROUTES.some((route) => config.url?.includes(route));
+
+ // if (!isPublic) {
+ // const token = AsyncStorage.getItem("authToken");
+ // if (token) {
+ // config.headers.Authorization = `Bearer ${token}`;
+ // } else {
+ // console.warn(`Token tidak ditemukan untuk endpoint: ${config.url}`);
+ // }
+ // }
+ return config;
+ },
+ (error) => {
+ return Promise.reject(error);
+ }
+);
+
export async function apiVersion() {
console.log("API_BASE_URL", API_BASE_URL);
const response = await apiClient.get("/version");
diff --git a/xcode.build.ios b/xcode.build.ios
new file mode 100644
index 0000000..8b688e5
--- /dev/null
+++ b/xcode.build.ios
@@ -0,0 +1 @@
+npx expo run:ios --device
\ No newline at end of file