mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Fixed login and revalidation page
This commit is contained in:
parent
9a246b45e1
commit
90f227a2c0
4 changed files with 19 additions and 19 deletions
|
@ -1,9 +1,9 @@
|
|||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
export const UserSlice = createSlice({
|
||||
name: "Auth",
|
||||
name: "User",
|
||||
initialState: {
|
||||
creds: {
|
||||
user: {
|
||||
email: "",
|
||||
uid: "",
|
||||
username: "",
|
||||
|
@ -17,7 +17,7 @@ export const UserSlice = createSlice({
|
|||
},
|
||||
reducers: {
|
||||
setUser: (state, action) => {
|
||||
state.creds = {
|
||||
state.user = {
|
||||
email: action.payload.email,
|
||||
uid: action.payload.uid,
|
||||
username: action.payload.username,
|
||||
|
@ -30,7 +30,7 @@ export const UserSlice = createSlice({
|
|||
};
|
||||
},
|
||||
clear: (state) => {
|
||||
state.creds = {
|
||||
state.user = {
|
||||
email: "",
|
||||
uid: "",
|
||||
username: "",
|
||||
|
|
|
@ -6,7 +6,7 @@ import { RootState } from "../../features/redux/Store/Store";
|
|||
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
|
||||
|
||||
export default function Home() {
|
||||
const creds = useSelector((state: RootState) => state.auth.creds);
|
||||
const creds = useSelector((state: RootState) => state.user.user);
|
||||
return (
|
||||
<View style={styles.background}>
|
||||
<AnimatedContainer>
|
||||
|
|
|
@ -17,13 +17,13 @@ import { RootDrawerParamList } from "../../interfaces/Interfaces";
|
|||
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/UserSlice/UserSlice";
|
||||
import { setUser } from "../../features/redux/slices/UserSlice/UserSlice";
|
||||
import { login } from "../../features/redux/slices/AuthSlice/AuthSlice";
|
||||
|
||||
export default function Login() {
|
||||
const navigation = useNavigation<RootDrawerParamList>();
|
||||
const dispatch = useDispatch();
|
||||
const [user, setUser] = useState({
|
||||
const [creds, setCreds] = useState({
|
||||
username: "",
|
||||
password: "",
|
||||
error: "",
|
||||
|
@ -51,11 +51,11 @@ export default function Login() {
|
|||
placeholder="Username"
|
||||
placeholderTextColor="white"
|
||||
autoCapitalize="none"
|
||||
value={user.username}
|
||||
value={creds.username}
|
||||
onChange={(
|
||||
e: NativeSyntheticEvent<TextInputChangeEventData>
|
||||
): void => {
|
||||
setUser({ ...user, username: e.nativeEvent.text });
|
||||
setUser({ ...creds, username: e.nativeEvent.text });
|
||||
}}
|
||||
/>
|
||||
<View style={{ paddingVertical: 4 }} />
|
||||
|
@ -64,27 +64,27 @@ export default function Login() {
|
|||
placeholder="Password"
|
||||
placeholderTextColor="white"
|
||||
secureTextEntry={true}
|
||||
value={user.password}
|
||||
value={creds.password}
|
||||
onChange={(
|
||||
e: NativeSyntheticEvent<TextInputChangeEventData>
|
||||
): void => {
|
||||
setUser({ ...user, password: e.nativeEvent.text });
|
||||
setUser({ ...creds, password: e.nativeEvent.text });
|
||||
}}
|
||||
/>
|
||||
<View style={{ paddingVertical: 2 }} />
|
||||
<Text style={styles.text_white_small}>{user.error}</Text>
|
||||
<Text style={styles.text_white_small}>{creds.error}</Text>
|
||||
<View style={{ paddingVertical: 4 }} />
|
||||
<Button
|
||||
onPress={async () => {
|
||||
await UserLogin({
|
||||
username: user.username,
|
||||
password: user.password,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
}).then(async (result) => {
|
||||
if (result[0]) {
|
||||
setUser({ ...user, username: "", password: "", error: "" });
|
||||
setUser({ ...creds, username: "", password: "", error: "" });
|
||||
let user_info = await UserInfo();
|
||||
dispatch(login());
|
||||
dispatch(setStateUser(user_info));
|
||||
console.log(dispatch(setUser(user_info[1])));
|
||||
// Redirect to onboarding if no year level, course, or semester specified
|
||||
if (
|
||||
user_info[1].year_level == null ||
|
||||
|
@ -98,7 +98,7 @@ export default function Login() {
|
|||
console.log(JSON.stringify(user_info));
|
||||
} else {
|
||||
setUser({
|
||||
...user,
|
||||
...creds,
|
||||
error: ParseLoginError(JSON.stringify(result[1])),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import { useEffect, useState } from "react";
|
|||
import { useNavigation } from "@react-navigation/native";
|
||||
import { RootDrawerParamList } from "../../interfaces/Interfaces";
|
||||
import { login } from "../../features/redux/slices/AuthSlice/AuthSlice";
|
||||
import { setUser } from "../../features/redux/slices/UserSlice/UserSlice";
|
||||
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
|
||||
import { setUser } from "../../features/redux/slices/UserSlice/UserSlice";
|
||||
|
||||
export default function Revalidation() {
|
||||
const dispatch = useDispatch();
|
||||
|
@ -21,7 +21,7 @@ export default function Revalidation() {
|
|||
let user_info = await UserInfo();
|
||||
if (response && user_info[0]) {
|
||||
dispatch(login());
|
||||
dispatch(setUser(user_info));
|
||||
console.log(dispatch(setUser(user_info[1])));
|
||||
if (
|
||||
!(
|
||||
user_info[1].year_level ||
|
||||
|
|
Loading…
Reference in a new issue