handle user profile session

This commit is contained in:
Jaanu423
2025-09-22 13:52:38 +05:30
18 changed files with 1537 additions and 711 deletions
+12 -11
View File
@@ -1,15 +1,16 @@
export const BASE_URL = "https://api.godemo.in/FundCollect/api/"
export const LOGIN_URL = `${BASE_URL}user/generate/otp?mobile=`
export const VARIFY_OTP_URL = `${BASE_URL}user/otp/verify`
export const ORGRAGISTRATION = `${BASE_URL}organizer/registration/apply`
export const GROUP_CREATION_URL = `${BASE_URL}fund/groups/{organizerId}`
export const PROFILE_URL =`${BASE_URL}user/profile/view`
export const PUBLIC_GROUPS_URL =`${BASE_URL}fund/user/public`
export const BASE_URL = "https://exotic-humpback-mistakenly.ngrok-free.app/api/"
// export const BASE_URL = "https://api.godemo.in/FundCollect/api/"
export const LOGIN_URL = `${BASE_URL}user/generate/otp?mobiles=`
export const VARIFY_OTP_URL = `${BASE_URL}user/otp/verify`
export const ORGRAGISTRATION = `${BASE_URL}organizer/registration/apply`
export const GROUP_CREATION_URL = `${BASE_URL}fund/groups/{organizerId}`
export const PROFILE_URL = `${BASE_URL}user/profile/view`
export const PUBLIC_GROUPS_URL = `${BASE_URL}fund/user/public`
export const JOIN_GROUP_URL = `${BASE_URL}fund/`;
export const MY_GROUPS_URL =`${BASE_URL}fund/getAll/my/groups`
export const REQUESTS_URL =`${BASE_URL}fund/group/pending/request`
export const APPROVE_REQUEST_URL =`${BASE_URL}fund/requests/`
export const DECLINE_REQUEST_URL =`${BASE_URL}fund/user/my/groups`
export const MY_GROUPS_URL = `${BASE_URL}fund/getAll/my/groups`
export const REQUESTS_URL = `${BASE_URL}fund/group/pending/request`
export const APPROVE_REQUEST_URL = `${BASE_URL}fund/requests/`
export const DECLINE_REQUEST_URL = `${BASE_URL}fund/user/my/groups`
export const GET_JOINED_GROUP_URL = `${BASE_URL}fund/my/join/groups`
export const PUT_USER_PROFILE_IMG = `${BASE_URL}user/update/userImg`
export const PUT_USER_PROFILE = `${BASE_URL}user/profile/update`
+53 -54
View File
@@ -4,59 +4,58 @@ import * as Keychain from "react-native-keychain";
import { setUserData } from "../redux/userSlice";
import { Alert } from "react-native";
export const fetchUserProfile = async () => {
const dispatch = useDispatch();
try {
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
// Alert.alert("Error", "You are not logged in");
return;
}
const token = credentials.password;
const response = await fetch(
`${BASE_URL}user/profile/view`,
{
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${token}`,
},
}
);
const result = await response.json();
if (result.status === "success") {
dispatch(setUserData({
id: result?.data.id,
userId: result?.data.userId,
username: result?.data.username,
firstName: result?.data.firstName,
lastName: result?.data.lastName,
gender: result?.data.gender,
mobile: result?.data.mobile,
email: result?.data.email,
address: result?.data.address,
bankAccountNumber: result?.data.bankAccountNumber,
bankName: result?.data.bankName,
branchCode: result?.data.branchCode,
profilePicture: result?.data.filePath, // or keep as `filePath`
filePath: result?.data.filePath,
imageBlob: result?.data.imageBlob,
role: result?.data.role,
organizerId: result?.data.organizerId,
organizerStatus: result?.data.organizerStatus,
profileStatus: true, // set true once profile is fetched
}));
console.log("splash user data:", result.data);
} else {
Alert.alert("Error", "Failed to fetch user profile");
}
} catch (error) {
console.error("❌ Error fetching profile:", error);
Alert.alert("Error", "Could not connect to server");
const dispatch = useDispatch();
try {
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
// Alert.alert("Error", "You are not logged in");
return;
}
const token = credentials.password;
const response = await fetch(
`${BASE_URL}user/profile/view`,
{
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${token}`,
},
}
};
);
const result = await response.json();
console.log("user api data", result)
if (result.status === "success") {
dispatch(setUserData({
id: result?.data.id,
userId: result?.data.userId,
username: result?.data.username,
firstName: result?.data.firstName,
lastName: result?.data.lastName,
gender: result?.data.gender,
mobile: result?.data.mobile,
email: result?.data.email,
address: result?.data.address,
bankAccountNumber: result?.data.bankAccountNumber,
bankName: result?.data.bankName,
branchCode: result?.data.branchCode,
profilePicture: result?.data.filePath, // or keep as `filePath`
filePath: result?.data.filePath,
imageBlob: result?.data.imageBlob,
role: result?.data.role,
organizerId: result?.data.organizerId,
organizerStatus: result?.data.organizerStatus,
profileStatus: true, // set true once profile is fetched
}));
console.log("splash user data:", result.data);
} else {
Alert.alert("Error", "Failed to fetch user profile");
}
} catch (error) {
console.error("❌ Error fetching profile:", error);
Alert.alert("Error", "Could not connect to server");
}
};