Polished revalidation and login. Opted to not store tokens anymore in state but only in asyncstorage

This commit is contained in:
Keannu Bernasol 2023-07-04 16:41:29 +08:00
parent 92b8ce0e4e
commit a027115836
5 changed files with 14 additions and 20 deletions

View file

@ -92,7 +92,7 @@ export async function TokenRefresh() {
"Token refresh success! New Access Token",
response.data.access
);*/
return [true, getAccessToken()];
return [true, JSON.stringify(response.data.access)];
})
.catch((error) => {
console.log("Refresh Failed: " + JSON.stringify(error.response.data));

View file

@ -53,7 +53,7 @@ export default function CustomDrawerContent(props: {}) {
<SignupIcon size={32} />
<Text style={styles.text_white_medium}>Register</Text>
</DrawerButton>
<DrawerButton
{/*<DrawerButton
color={colors.blue_2}
onPress={() => {
navigation.navigate("Revalidation");
@ -71,6 +71,7 @@ export default function CustomDrawerContent(props: {}) {
<AddIcon size={32} />
<Text style={styles.text_white_medium}>Activation</Text>
</DrawerButton>
*/}
</DrawerContentScrollView>
);
}

View file

@ -8,14 +8,12 @@ export const AuthSlice = createSlice({
uid: "",
username: "",
full_name: "",
refresh_token: "",
access_token: "",
logged_in: false,
},
},
reducers: {
setToken: (state, action) => {
state.creds.access_token = action.payload.access_token;
state.creds.refresh_token = action.payload.refresh_token;
login: (state) => {
state.creds.logged_in = true;
},
setUser: (state, action) => {
state.creds = {
@ -23,8 +21,7 @@ export const AuthSlice = createSlice({
uid: action.payload.uid,
username: action.payload.username,
full_name: action.payload.full_name,
access_token: action.payload.access_token,
refresh_token: action.payload.refresh_token,
logged_in: true,
};
},
clear: (state) => {
@ -33,14 +30,13 @@ export const AuthSlice = createSlice({
uid: "",
username: "",
full_name: "",
refresh_token: "",
access_token: "",
logged_in: false,
};
},
},
});
// 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;

View file

@ -8,7 +8,6 @@ import {
TextInputChangeEventData,
} from "react-native";
import { useDispatch } from "react-redux";
import { setToken } from "../../features/redux/slices/AuthSlice/AuthSlice";
import { colors } from "../../styles";
import { useState } from "react";
import LoginIcon from "../../icons/LoginIcon/LoginIcon";
@ -87,12 +86,6 @@ export default function Login() {
"\nRefresh Token:",
result[2]
);*/
dispatch(
setToken({
access_token: result[1],
refresh_token: result[2],
})
);
navigation.navigate("Onboarding");
} else {
setUser({

View file

@ -1,7 +1,11 @@
import * as React from "react";
import styles from "../../styles";
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 { colors } from "../../styles";
import { useEffect, useState } from "react";