Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add login with OpenStreetMap- Oauth 2.0 #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"core-js": "^3.6.5",
"jquery": "^3.6.0",
"mapbox-gl": "^2.3.0",
"osm-auth": "^2.0.0",
"popper.js": "^1.16.1",
"vue": "^2.6.11",
"vue-analytics": "^5.22.1",
Expand All @@ -30,6 +31,7 @@
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "^4.5.13",
"babel-eslint": "^10.1.0",
"dotenv-webpack": "^8.0.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.32.0",
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/app/public/land.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>

<head></head>

<body>
<script>
opener.authComplete(window.location.href);
window.close();
</script>
</body>

</html>
41 changes: 37 additions & 4 deletions frontend/src/app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@
>
<!-- Provision before-after map with ease -->
<v-spacer></v-spacer>

<!-- <v-btn @click="darkMode" icon v-bind:style="{ marginRight: '15px' }">
<v-icon>mdi-invert-colors</v-icon>
</v-btn> -->
<v-btn
v-if="!userAuthenticated"
color="#47889d"
@click="loginWithOSM"
class="text-white"
>
Login with OSM
</v-btn>
<v-btn
v-if="userAuthenticated"
color="#47889d"
@click="logoutFromOSM"
class="text-white"
>
Logout
</v-btn>
</v-app-bar>
<About :aboutDialog="aboutDialog" :closeAboutDialog="closeAboutDialog" />
<v-main>
Expand Down Expand Up @@ -59,6 +71,16 @@ import About from "./components/About";
import ProvisionInstance from "./components/ProvisionInstance";
import SytemNotWorking from "./components/NotWorking.vue";
import Tour from "./components/Tour";
import { osmAuth } from "osm-auth";

const redirectPath = window.location.origin + window.location.pathname;
const auth = osmAuth({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
redirect_uri: redirectPath + "land.html",
scope: "read_prefs",
auto: true, // show a login form if the user is not authenticated and you try to do a call
});

export default {
name: "App",
Expand All @@ -73,9 +95,11 @@ export default {
data: () => ({
aboutDialog: false,
systemNotWorking: false,
userAuthenticated: auth && auth.authenticated() ? true : false,
}),
created() {
this.$gtag.pageview("/");
if (auth && auth.authenticated()) this.loginWithOSM();
},
methods: {
closeAboutDialog() {
Expand All @@ -92,6 +116,15 @@ export default {
darkMode() {
this.$vuetify.theme.dark = !this.$vuetify.theme.dark;
},
loginWithOSM() {
auth.xhr({ method: "GET", path: "/api/0.6/user/details" }, () => {
this.userAuthenticated = true;
});
},
logoutFromOSM() {
auth.logout();
this.userAuthenticated = false;
},
toggleTour() {
this.$gtag.event("click", {
event_category: "Viewed tour",
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const Dotenv = require('dotenv-webpack');


module.exports = {
transpileDependencies: [
'vuetify'
],
devServer: {
disableHostCheck: true
},
configureWebpack: {
plugins: [
new Dotenv()
]
}
}