@@ -50,35 +50,42 @@ export default {
50
50
methods: {
51
51
showInstagramAlert () {
52
52
alert (" This feature will be rolled out soon. Stay tuned." );
53
+ },
54
+ fetchUserData () {
55
+ if (navigator .geolocation ) {
56
+ navigator .geolocation .getCurrentPosition (async (position ) => {
57
+ this .latitude = position .coords .latitude ;
58
+ this .longitude = position .coords .longitude ;
59
+ this .loading = true ;
60
+
61
+ try {
62
+ const url = ` ${ this .$globalData .backendUrl } /studybuddy/` ;
63
+ const response = await axios .post (url, {
64
+ token2: this .token2 ,
65
+ latitude: this .latitude ,
66
+ longitude: this .longitude
67
+ });
68
+
69
+ this .users = response .data ;
70
+ } catch (error) {
71
+ alert (error .response ? .data ? .error || ' An error occurred' );
72
+ } finally {
73
+ this .loading = false ;
74
+ }
75
+ }, (error ) => {
76
+ alert (' Geolocation not supported or permission denied' );
77
+ });
78
+ } else {
79
+ alert (' Geolocation is not supported by this browser.' );
80
+ }
53
81
}
54
82
},
55
- async mounted () {
56
-
57
- if (navigator .geolocation ) {
58
- navigator .geolocation .getCurrentPosition (async (position ) => {
59
- this .latitude = position .coords .latitude ;
60
- this .longitude = position .coords .longitude ;
61
- this .loading = true ;
62
-
63
- try {
64
- const url = ` ${ this .$globalData .backendUrl } /studybuddy/` ;
65
- const response = await axios .post (url, {
66
- token2: this .token2 ,
67
- latitude: this .latitude ,
68
- longitude: this .longitude
69
- });
70
-
71
- this .users = response .data ;
72
- } catch (error) {
73
- alert (error .response ? .data ? .error || ' An error occurred' );
74
- } finally {
75
- this .loading = false ;
76
- }
77
- }, (error ) => {
78
- alert (' Geolocation not supported or permission denied' );
79
- });
80
- } else {
81
- alert (' Geolocation is not supported by this browser.' );
83
+ mounted () {
84
+ if (this .token2 ) {
85
+ this .fetchUserData ();
86
+ }
87
+ else {
88
+ alert (" Login with IITM Google Account & Give Location Access" )
82
89
}
83
90
}
84
91
};
0 commit comments