mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Redirect to onboarding page if needed and added some missing functionality to login and logout button
This commit is contained in:
parent
a9acff39e4
commit
90e60250cd
4 changed files with 32 additions and 13 deletions
|
@ -70,7 +70,7 @@ export function UserLogin(user: LoginParams) {
|
||||||
return [true];
|
return [true];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Login Failed:" + error.response.data);
|
console.log("Login Failed:" + JSON.stringify(error.response.data));
|
||||||
return [false, error.response.data];
|
return [false, error.response.data];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default function CustomDrawerContent(props: {}) {
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
dispatch(await clear());
|
dispatch(await clear());
|
||||||
await AsyncStorage.clear();
|
await AsyncStorage.clear();
|
||||||
navigation.navigate("Home");
|
navigation.navigate("Login");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LogoutIcon size={32} />
|
<LogoutIcon size={32} />
|
||||||
|
|
|
@ -14,9 +14,10 @@ import LoginIcon from "../../icons/LoginIcon/LoginIcon";
|
||||||
import Button from "../../components/Button/Button";
|
import Button from "../../components/Button/Button";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import { RootDrawerParamList } from "../../interfaces/Interfaces";
|
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 { ParseLoginError } from "../../components/ParseError/ParseError";
|
||||||
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
|
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
|
||||||
|
import { setUser as setStateUser } from "../../features/redux/slices/AuthSlice/AuthSlice";
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const navigation = useNavigation<RootDrawerParamList>();
|
const navigation = useNavigation<RootDrawerParamList>();
|
||||||
|
@ -77,10 +78,32 @@ export default function Login() {
|
||||||
await UserLogin({
|
await UserLogin({
|
||||||
username: user.username,
|
username: user.username,
|
||||||
password: user.password,
|
password: user.password,
|
||||||
}).then((result) => {
|
}).then(async (result) => {
|
||||||
if (result[0]) {
|
if (result[0]) {
|
||||||
setUser({ ...user, username: "", password: "", error: "" });
|
setUser({ ...user, username: "", password: "", error: "" });
|
||||||
|
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");
|
navigation.navigate("Onboarding");
|
||||||
|
} else {
|
||||||
|
navigation.navigate("Home");
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(user_info));
|
||||||
} else {
|
} else {
|
||||||
setUser({
|
setUser({
|
||||||
...user,
|
...user,
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { View, Text, ActivityIndicator } from "react-native";
|
import { View, Text, ActivityIndicator } from "react-native";
|
||||||
import {
|
import { TokenRefresh, UserInfo } from "../../components/Api/Api";
|
||||||
TokenRefresh,
|
|
||||||
UserInfo,
|
|
||||||
setAccessToken,
|
|
||||||
} from "../../components/Api/Api";
|
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { colors } from "../../styles";
|
import { colors } from "../../styles";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
@ -23,12 +19,12 @@ export default function Revalidation() {
|
||||||
TokenRefresh().then(async (response) => {
|
TokenRefresh().then(async (response) => {
|
||||||
if (response[0]) {
|
if (response[0]) {
|
||||||
await dispatch(setUser(await UserInfo()));
|
await dispatch(setUser(await UserInfo()));
|
||||||
setTimeout(() => {
|
await setTimeout(() => {
|
||||||
navigation.navigate("Home");
|
navigation.navigate("Home");
|
||||||
}, 700);
|
}, 700);
|
||||||
} else {
|
} else {
|
||||||
setState("Session expired");
|
await setState("Session expired");
|
||||||
setTimeout(() => {
|
await setTimeout(() => {
|
||||||
navigation.navigate("Login");
|
navigation.navigate("Login");
|
||||||
}, 700);
|
}, 700);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue