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