mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Polished revalidation and login. Opted to not store tokens anymore in state but only in asyncstorage
This commit is contained in:
parent
92b8ce0e4e
commit
a027115836
5 changed files with 14 additions and 20 deletions
|
@ -92,7 +92,7 @@ export async function TokenRefresh() {
|
||||||
"Token refresh success! New Access Token",
|
"Token refresh success! New Access Token",
|
||||||
response.data.access
|
response.data.access
|
||||||
);*/
|
);*/
|
||||||
return [true, getAccessToken()];
|
return [true, JSON.stringify(response.data.access)];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Refresh Failed: " + JSON.stringify(error.response.data));
|
console.log("Refresh Failed: " + JSON.stringify(error.response.data));
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default function CustomDrawerContent(props: {}) {
|
||||||
<SignupIcon size={32} />
|
<SignupIcon size={32} />
|
||||||
<Text style={styles.text_white_medium}>Register</Text>
|
<Text style={styles.text_white_medium}>Register</Text>
|
||||||
</DrawerButton>
|
</DrawerButton>
|
||||||
<DrawerButton
|
{/*<DrawerButton
|
||||||
color={colors.blue_2}
|
color={colors.blue_2}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
navigation.navigate("Revalidation");
|
navigation.navigate("Revalidation");
|
||||||
|
@ -71,6 +71,7 @@ export default function CustomDrawerContent(props: {}) {
|
||||||
<AddIcon size={32} />
|
<AddIcon size={32} />
|
||||||
<Text style={styles.text_white_medium}>Activation</Text>
|
<Text style={styles.text_white_medium}>Activation</Text>
|
||||||
</DrawerButton>
|
</DrawerButton>
|
||||||
|
*/}
|
||||||
</DrawerContentScrollView>
|
</DrawerContentScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,12 @@ export const AuthSlice = createSlice({
|
||||||
uid: "",
|
uid: "",
|
||||||
username: "",
|
username: "",
|
||||||
full_name: "",
|
full_name: "",
|
||||||
refresh_token: "",
|
logged_in: false,
|
||||||
access_token: "",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
setToken: (state, action) => {
|
login: (state) => {
|
||||||
state.creds.access_token = action.payload.access_token;
|
state.creds.logged_in = true;
|
||||||
state.creds.refresh_token = action.payload.refresh_token;
|
|
||||||
},
|
},
|
||||||
setUser: (state, action) => {
|
setUser: (state, action) => {
|
||||||
state.creds = {
|
state.creds = {
|
||||||
|
@ -23,8 +21,7 @@ export const AuthSlice = createSlice({
|
||||||
uid: action.payload.uid,
|
uid: action.payload.uid,
|
||||||
username: action.payload.username,
|
username: action.payload.username,
|
||||||
full_name: action.payload.full_name,
|
full_name: action.payload.full_name,
|
||||||
access_token: action.payload.access_token,
|
logged_in: true,
|
||||||
refresh_token: action.payload.refresh_token,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
clear: (state) => {
|
clear: (state) => {
|
||||||
|
@ -33,14 +30,13 @@ export const AuthSlice = createSlice({
|
||||||
uid: "",
|
uid: "",
|
||||||
username: "",
|
username: "",
|
||||||
full_name: "",
|
full_name: "",
|
||||||
refresh_token: "",
|
logged_in: false,
|
||||||
access_token: "",
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Action creators are generated for each case reducer function
|
// Action creators are generated for each case reducer function
|
||||||
export const { setToken, setUser, clear } = AuthSlice.actions;
|
export const { login, setUser, clear } = AuthSlice.actions;
|
||||||
|
|
||||||
export default AuthSlice.reducer;
|
export default AuthSlice.reducer;
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
TextInputChangeEventData,
|
TextInputChangeEventData,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { setToken } from "../../features/redux/slices/AuthSlice/AuthSlice";
|
|
||||||
import { colors } from "../../styles";
|
import { colors } from "../../styles";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import LoginIcon from "../../icons/LoginIcon/LoginIcon";
|
import LoginIcon from "../../icons/LoginIcon/LoginIcon";
|
||||||
|
@ -87,12 +86,6 @@ export default function Login() {
|
||||||
"\nRefresh Token:",
|
"\nRefresh Token:",
|
||||||
result[2]
|
result[2]
|
||||||
);*/
|
);*/
|
||||||
dispatch(
|
|
||||||
setToken({
|
|
||||||
access_token: result[1],
|
|
||||||
refresh_token: result[2],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
navigation.navigate("Onboarding");
|
navigation.navigate("Onboarding");
|
||||||
} else {
|
} else {
|
||||||
setUser({
|
setUser({
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
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 { TokenRefresh, UserInfo } from "../../components/Api/Api";
|
import {
|
||||||
|
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";
|
||||||
|
|
Loading…
Reference in a new issue