Redirect to onboarding page if needed and added some missing functionality to login and logout button

This commit is contained in:
Keannu Bernasol 2023-07-04 21:01:56 +08:00
parent a9acff39e4
commit 90e60250cd
4 changed files with 32 additions and 13 deletions

View file

@ -70,7 +70,7 @@ export function UserLogin(user: LoginParams) {
return [true];
})
.catch((error) => {
console.log("Login Failed:" + error.response.data);
console.log("Login Failed:" + JSON.stringify(error.response.data));
return [false, error.response.data];
});
}

View file

@ -49,7 +49,7 @@ export default function CustomDrawerContent(props: {}) {
onPress={async () => {
dispatch(await clear());
await AsyncStorage.clear();
navigation.navigate("Home");
navigation.navigate("Login");
}}
>
<LogoutIcon size={32} />

View file

@ -14,9 +14,10 @@ import LoginIcon from "../../icons/LoginIcon/LoginIcon";
import Button from "../../components/Button/Button";
import { useNavigation } from "@react-navigation/native";
import { RootDrawerParamList } from "../../interfaces/Interfaces";
import { UserLogin } from "../../components/Api/Api";
import { UserInfo, UserLogin } from "../../components/Api/Api";
import { ParseLoginError } from "../../components/ParseError/ParseError";
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
import { setUser as setStateUser } from "../../features/redux/slices/AuthSlice/AuthSlice";
export default function Login() {
const navigation = useNavigation<RootDrawerParamList>();
@ -77,10 +78,32 @@ export default function Login() {
await UserLogin({
username: user.username,
password: user.password,
}).then((result) => {
}).then(async (result) => {
if (result[0]) {
setUser({ ...user, username: "", password: "", error: "" });
navigation.navigate("Onboarding");
let user_info = await UserInfo();
dispatch(setStateUser(user_info));
// Redirect to onboarding if no year level, course, or semester specified
console.log(
"Debug",
!(
user_info.year_level ||
user_info.course ||
user_info.semester
)
);
if (
!(
user_info.year_level ||
user_info.course ||
user_info.semester
)
) {
navigation.navigate("Onboarding");
} else {
navigation.navigate("Home");
}
console.log(JSON.stringify(user_info));
} else {
setUser({
...user,

View file

@ -1,11 +1,7 @@
import * as React from "react";
import styles from "../../styles";
import { View, Text, ActivityIndicator } from "react-native";
import {
TokenRefresh,
UserInfo,
setAccessToken,
} from "../../components/Api/Api";
import { TokenRefresh, UserInfo } from "../../components/Api/Api";
import { useDispatch } from "react-redux";
import { colors } from "../../styles";
import { useEffect, useState } from "react";
@ -23,12 +19,12 @@ export default function Revalidation() {
TokenRefresh().then(async (response) => {
if (response[0]) {
await dispatch(setUser(await UserInfo()));
setTimeout(() => {
await setTimeout(() => {
navigation.navigate("Home");
}, 700);
} else {
setState("Session expired");
setTimeout(() => {
await setState("Session expired");
await setTimeout(() => {
navigation.navigate("Login");
}, 700);
}