Enable logging out by revoking the access token
This commit is contained in:
parent
856f215e36
commit
6d0bfa8fd7
|
@ -13,6 +13,7 @@ import {
|
||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
|
||||||
import { withoutHTML } from "src/interface/rendering";
|
import { withoutHTML } from "src/interface/rendering";
|
||||||
|
import * as requests from "src/requests";
|
||||||
|
|
||||||
import { ScreenWithBackBarJsx } from "src/components/navigation/navigators";
|
import { ScreenWithBackBarJsx } from "src/components/navigation/navigators";
|
||||||
|
|
||||||
|
@ -46,12 +47,68 @@ const SettingsJsx = (props) => {
|
||||||
// Use Context to get this stuff eventually
|
// Use Context to get this stuff eventually
|
||||||
profile: TEST_PROFILE,
|
profile: TEST_PROFILE,
|
||||||
newProfile: TEST_PROFILE,
|
newProfile: TEST_PROFILE,
|
||||||
|
loaded: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const fields = state.newProfile.fields;
|
const fields = state.newProfile.fields;
|
||||||
|
|
||||||
|
const _handleLogout = async () => {
|
||||||
|
await requests.postForm(
|
||||||
|
`https://${state.instance}/oauth/revoke`,
|
||||||
|
{
|
||||||
|
client_id: state.appObject.client_id,
|
||||||
|
client_secret: state.appObject.client_secret,
|
||||||
|
token: state.token.access_token,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await AsyncStorage.multiRemove([
|
||||||
|
"@user_profile",
|
||||||
|
"@user_notifications",
|
||||||
|
"@user_instance",
|
||||||
|
"@user_token",
|
||||||
|
]);
|
||||||
|
|
||||||
|
props.navigation.navigate("Authenticate");
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
AsyncStorage
|
||||||
|
.multiGet([
|
||||||
|
"@user_profile",
|
||||||
|
"@user_instance",
|
||||||
|
"@user_token",
|
||||||
|
"@app_object",
|
||||||
|
])
|
||||||
|
.then(([profilePair, instancePair, tokenPair, appPair]) =>
|
||||||
|
[
|
||||||
|
JSON.parse(profilePair[1]),
|
||||||
|
instancePair[1],
|
||||||
|
JSON.parse(tokenPair[1]),
|
||||||
|
JSON.parse(appPair[1]),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.then(([profile, instance, token, appObject]) => {
|
||||||
|
let newProfile = profile;
|
||||||
|
newProfile.fields = newProfile.fields == null
|
||||||
|
? []
|
||||||
|
: newProfile.fields;
|
||||||
|
|
||||||
|
setState({...state,
|
||||||
|
profile: profile,
|
||||||
|
newProfile: newProfile,
|
||||||
|
instance: instance,
|
||||||
|
appObject: appObject,
|
||||||
|
token: token,
|
||||||
|
loaded: true,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScreenWithBackBarJsx navigation = { props.navigation }>
|
<>
|
||||||
|
{ state.loaded
|
||||||
|
? <ScreenWithBackBarJsx navigation = { props.navigation }>
|
||||||
<View style = { styles.avatar.container }>
|
<View style = { styles.avatar.container }>
|
||||||
<Image
|
<Image
|
||||||
source = { { uri: state.profile.avatar } }
|
source = { { uri: state.profile.avatar } }
|
||||||
|
@ -207,15 +264,7 @@ const SettingsJsx = (props) => {
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style = { styles.button.container }
|
style = { styles.button.container }
|
||||||
onPress = {
|
onPress = { _handleLogout }>
|
||||||
() => {
|
|
||||||
AsyncStorage.multiRemove(
|
|
||||||
["@user_profile", "@user_notifications"]
|
|
||||||
).then(() => {
|
|
||||||
props.navigation.navigate("Authenticate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}>
|
|
||||||
<Text style = {
|
<Text style = {
|
||||||
[ styles.button.text, styles.button.warning ]
|
[ styles.button.text, styles.button.warning ]
|
||||||
}>
|
}>
|
||||||
|
@ -224,6 +273,9 @@ const SettingsJsx = (props) => {
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
</ScreenWithBackBarJsx>
|
</ScreenWithBackBarJsx>
|
||||||
|
: <></>
|
||||||
|
}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue