Account.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import React, { useEffect } from 'react';
  2. import { Image, ImageBackground, StyleSheet, View, TouchableOpacity, } from 'react-native';
  3. import { Text, } from 'react-native-paper'
  4. import 'react-native-get-random-values';
  5. import { useAuthState } from '../contexts/AuthContext';
  6. import { useMapState } from '../contexts/MapContext';
  7. import * as SecureStore from 'expo-secure-store';
  8. import axios from 'axios';
  9. const Account = ({navigation}) => {
  10. useEffect(() => {
  11. const getUserInfo = async () => {
  12. try {
  13. const response = await axios.get(`http://10.0.0.151:8000/api/me/`, {
  14. headers: {
  15. "Authorization": "Bearer " + await SecureStore.getItemAsync('accessToken')
  16. }
  17. });
  18. console.log(response.data);
  19. }
  20. catch (error) {
  21. console.log(error.request.headers);
  22. console.log(error.response.data);
  23. }
  24. }
  25. getUserInfo();
  26. }, []);
  27. const {mapState, state} = useMapState();
  28. const {authDispatch, authState} = useAuthState();
  29. const checkAccessToken = async () => {
  30. console.log(await SecureStore.getItemAsync('accessToken'));
  31. }
  32. const checkIdToken = async () => {
  33. console.log(authState.idToken);
  34. }
  35. const revokeToken = async () => {
  36. const tokenParams = new URLSearchParams();
  37. tokenParams.append('token', await SecureStore.getItemAsync('accessToken'));
  38. tokenParams.append('client_id', 'atlas.clicknpush');
  39. try {
  40. const response = await axios.post(`http://10.0.0.151:8000/o/revoke_token/`, tokenParams, {
  41. headers: {
  42. 'Content-Type': 'application/x-www-form-urlencoded'
  43. }
  44. });
  45. await SecureStore.deleteItemAsync('accessToken');
  46. authDispatch({type: 'SET_ACCESS_TOKEN', payload: ''});
  47. }
  48. catch (error) {
  49. console.log(error.response.data);
  50. }
  51. }
  52. return(
  53. <ImageBackground style={styles.container} source={require('../assets/cover.jpg')}>
  54. <View style={styles.contentContainer}>
  55. <Image style={styles.pfp} source={require('../assets/default-pfp.png')}/>
  56. <View style={styles.quickStats}>
  57. {/* <Text>{state.rank}</Text>
  58. <Text>{state.landmarks.filter(l => l.postedBy == state.username).length}</Text> */}
  59. <Text></Text>
  60. </View>
  61. <TouchableOpacity style={styles.registerBtn} onPress={checkAccessToken} >
  62. <Text style={{ color: 'white', fontSize: 15 }}>Check access token</Text>
  63. </TouchableOpacity>
  64. <TouchableOpacity style={styles.registerBtn} onPress={checkIdToken} >
  65. <Text style={{ color: 'white', fontSize: 15 }}>Check id token</Text>
  66. </TouchableOpacity>
  67. <TouchableOpacity style={styles.registerBtn} onPress={revokeToken} >
  68. <Text style={{ color: 'white', fontSize: 15 }}>Revoke token</Text>
  69. </TouchableOpacity>
  70. </View>
  71. </ImageBackground>
  72. )
  73. }
  74. const styles = StyleSheet.create({
  75. container: {
  76. flex: 1,
  77. justifyContent: 'flex-end'
  78. },
  79. contentContainer: {
  80. backgroundColor: '#df3f3f',
  81. height: '80%',
  82. alignItems: 'center'
  83. },
  84. pfp: {
  85. marginTop: -75,
  86. borderRadius: 75,
  87. zIndex: 5,
  88. height: 150,
  89. width: 150,
  90. },
  91. quickStats: {
  92. width: '100%',
  93. marginTop: 50,
  94. flexDirection: 'row',
  95. justifyContent: 'space-evenly',
  96. },
  97. title: {
  98. fontFamily: 'RacingSansOne-Regular',
  99. marginTop: 30,
  100. color: 'white',
  101. fontSize: 30
  102. },
  103. textContainer: {
  104. marginHorizontal: 20,
  105. borderRadius: 50,
  106. },
  107. textInput: {
  108. marginBottom: 10,
  109. paddingLeft: 30,
  110. borderRadius: 50,
  111. overflow: 'hidden',
  112. backgroundColor: 'white',
  113. height: 50
  114. },
  115. loginBtn: {
  116. borderRadius: 50,
  117. width: 170,
  118. marginLeft: 10,
  119. justifyContent: 'center',
  120. backgroundColor: '#df3f3f',
  121. height: 60,
  122. alignItems: 'center'
  123. },
  124. registerBtn: {
  125. width: 170,
  126. marginRight: 10,
  127. borderColor: 'white',
  128. borderWidth: 2,
  129. borderRadius: 50,
  130. justifyContent: 'center',
  131. backgroundColor: 'transparent',
  132. height: 60,
  133. alignItems: 'center'
  134. },
  135. btnContainer: {
  136. flexDirection: 'row-reverse',
  137. justifyContent: 'center'
  138. },
  139. })
  140. export default Account;