Skip to content

Commit

Permalink
Merge pull request #173 from COS301-SE-2024/chore/mobile/endpoints
Browse files Browse the repository at this point in the history
Chore/mobile/endpoints
  • Loading branch information
KamogeloMoeketse authored Jul 9, 2024
2 parents ad6b72f + 37b98ee commit d1d1073
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 3 additions & 1 deletion frontend/occupi-mobile4/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ google-services.json
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
# @end expo-cli

.env
8 changes: 6 additions & 2 deletions frontend/occupi-mobile4/screens/Login/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const SignInForm = () => {
} = useForm<SignInSchemaType>({
resolver: zodResolver(signInSchema),
});
const apiUrl = process.env.EXPO_PUBLIC_DEVELOP_API_URL;
const loginUrl = process.env.EXPO_PUBLIC_LOGIN;
const getUserDetailsUrl= process.env.EXPO_PUBLIC_GET_USER_DETAILS;
console.log(apiUrl,loginUrl);
const isEmailFocused = useState(false);
const [loading, setLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
Expand Down Expand Up @@ -155,7 +159,7 @@ const SignInForm = () => {
const onSubmit = async (_data: SignInSchemaType) => {
setLoading(true);
try {
const response = await fetch('https://dev.occupi.tech/auth/login-mobile', {
const response = await fetch(`${apiUrl}${loginUrl}`, {
method: 'POST',
headers: {
Accept: 'application/json',
Expand Down Expand Up @@ -186,7 +190,7 @@ const SignInForm = () => {
let authToken = await SecureStore.getItemAsync('Token');
// console.log(authToken);

const response = await fetch(`https://dev.occupi.tech/api/user-details?email=${_data.email}`, {
const response = await fetch(`${apiUrl}${getUserDetailsUrl}?email=${_data.email}`, {
method: 'GET',
headers: {
Accept: 'application/json',
Expand Down
21 changes: 18 additions & 3 deletions frontend/occupi-mobile4/screens/Settings/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const Profile = () => {
const [isLoading, setIsLoading] = useState(false);
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
let colorScheme = useColorScheme();
const apiUrl = process.env.EXPO_PUBLIC_DEVELOP_API_URL;
const getUserDetailsUrl= process.env.EXPO_PUBLIC_GET_USER_DETAILS;
const updateDetailsUrl = process.env.EXPO_PUBLIC_UPDATE_USER_DETAILS;
console.log(apiUrl, getUserDetailsUrl, updateDetailsUrl);

useEffect(() => {
const getUserDetails = async () => {
Expand Down Expand Up @@ -115,11 +119,13 @@ const Profile = () => {
// console.log(JSON.stringify(body));
setIsLoading(true);
try {
const response = await fetch('https://dev.occupi.tech/api/update-user', {
let authToken = await SecureStore.getItemAsync('Token');
const response = await fetch(`${apiUrl}${updateDetailsUrl}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'Authorization': `${authToken}`
},
body: JSON.stringify(body),
credentials: "include"
Expand All @@ -141,7 +147,16 @@ const Profile = () => {
}

try {
const response = await fetch(`https://dev.occupi.tech/api/user-details?email=${email}`)
let authToken = await SecureStore.getItemAsync('Token');
const response = await fetch(`${apiUrl}${getUserDetailsUrl}?email=${email}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': `${authToken}`
},
credentials: "include"
});
const data = await response.json();
if (response.ok) {
saveUserData(JSON.stringify(data));
Expand Down

0 comments on commit d1d1073

Please sign in to comment.