Skip to content

Commit 6dddebc

Browse files
authored
Merge pull request #67 from mapswipe/17-enhancement-add-the-ability-to-sign-in-using-an-osm-account
17 enhancement add the ability to sign in using an osm account
2 parents 83ea775 + ce894d1 commit 6dddebc

File tree

12 files changed

+153
-4
lines changed

12 files changed

+153
-4
lines changed

.env.development.local.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ VITE_FIREBASE_APP_ID=
1010
VITE_FIREBASE_MEASUREMENT_ID=
1111

1212
VITE_MAPILLARY_API_KEY=
13+
14+
VITE_OSM_OAUTH_REDIRECT_URI=

.env.production.local.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ VITE_FIREBASE_APP_ID=
1010
VITE_FIREBASE_MEASUREMENT_ID=
1111

1212
VITE_MAPILLARY_API_KEY=
13+
14+
VITE_OSM_OAUTH_REDIRECT_URI=

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
VITE_FIREBASE_MESSAGING_SENDER_ID: "${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID }}"
5454
VITE_FIREBASE_APP_ID: "${{ secrets.VITE_FIREBASE_APP_ID }}"
5555
VITE_MAPILLARY_API_KEY: "${{ secrets.VITE_MAPILLARY_API_KEY }}"
56+
VITE_OSM_OAUTH_REDIRECT_URI: "${{ secrets.VITE_OSM_OAUTH_REDIRECT_URI }}"
5657
run: yarn build-ghpages-dev # or pnpm docs:build / yarn docs:build / bun run docs:build
5758
- name: Checkout latest release tag
5859
run: |
@@ -71,6 +72,7 @@ jobs:
7172
VITE_FIREBASE_MESSAGING_SENDER_ID: "${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID_PROD }}"
7273
VITE_FIREBASE_APP_ID: "${{ secrets.VITE_FIREBASE_APP_ID_PROD }}"
7374
VITE_MAPILLARY_API_KEY: "${{ secrets.VITE_MAPILLARY_API_KEY }}"
75+
VITE_OSM_OAUTH_REDIRECT_URI: "${{ secrets.VITE_OSM_OAUTH_REDIRECT_URI_PROD }}"
7476
run: yarn build-ghpages-prod
7577
- name: Move the prod build to parent folder
7678
run: mv docs/dist/prod/* docs/dist/.

src/components/OauthReturn.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script lang="ts">
2+
import { defineComponent } from 'vue'
3+
import { i18nRoute } from '@/i18n/translation'
4+
import { signInWithCustomToken, getAuth } from 'firebase/auth'
5+
import { logAnalyticsEvent } from '@/firebase'
6+
7+
export default defineComponent({
8+
props: {
9+
token: String,
10+
},
11+
inject: {
12+
showSnackbar: 'showSnackbar',
13+
},
14+
methods: {
15+
i18nRoute,
16+
signin(token: String) {
17+
const routerReplace = this.$router.replace
18+
const auth = getAuth()
19+
signInWithCustomToken(auth, token)
20+
.then(() => {
21+
this.showSnackbar(this.$t('authView.osmSignInSuccess'), 'success')
22+
logAnalyticsEvent('account_login')
23+
routerReplace(i18nRoute({ name: 'projects' }))
24+
})
25+
.catch(() => {
26+
this.showSnackbar(this.$t('authView.osmSignInError'), 'error')
27+
routerReplace(i18nRoute({ name: 'authentication', params: { authTab: 'sign-in' } }))
28+
})
29+
},
30+
},
31+
mounted() {
32+
this.signin(this.token)
33+
},
34+
})
35+
</script>
36+
37+
<template>
38+
<p></p>
39+
</template>

src/components/SignIn.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { defineComponent } from 'vue'
33
import { i18nRoute } from '@/i18n/translation'
44
import { signInWithEmailAndPassword, getAuth } from 'firebase/auth'
55
import { logAnalyticsEvent } from '@/firebase'
6+
import SignInOsm from '@/components/SignInOsm.vue'
67
78
export default defineComponent({
9+
components: {
10+
signInOsm: SignInOsm,
11+
},
812
data() {
913
return {
1014
isFormValid: false,
@@ -119,6 +123,7 @@ export default defineComponent({
119123
</router-link>
120124
</div>
121125
</v-col>
126+
<sign-in-osm />
122127
</v-form>
123128
</v-container>
124129
</template>

src/components/SignInOsm.vue

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script lang="ts">
2+
import { defineComponent } from 'vue'
3+
4+
export default defineComponent({
5+
data() {
6+
return {
7+
consent: false,
8+
}
9+
},
10+
computed: {
11+
osmOAuthRedirectUri() {
12+
const uri = import.meta.env.VITE_OSM_OAUTH_REDIRECT_URI
13+
return uri
14+
},
15+
privacyPolicyUrl() {
16+
const url = import.meta.env.VITE_PRIVACY_POLICY_URL
17+
const locale = this.$i18n.locale
18+
return url.replace('{locale}', locale)
19+
},
20+
},
21+
methods: {
22+
signInOSM() {
23+
window.location.href = this.osmOAuthRedirectUri
24+
},
25+
},
26+
})
27+
</script>
28+
29+
<template>
30+
<v-dialog max-width="800">
31+
<template v-slot:activator="{ props: activatorProps }">
32+
<v-col v-if="osmOAuthRedirectUri" class="text-center">
33+
<v-divider />
34+
<br />
35+
{{ $t('authView.or') }}
36+
<br /><br />
37+
<v-btn color="primary" v-bind="activatorProps" depressed>
38+
{{ $t('authView.signInOsm') }}
39+
</v-btn>
40+
</v-col>
41+
</template>
42+
<template v-slot:default>
43+
<v-card>
44+
<v-card-text>
45+
{{ $t('authView.signInOsmText') }}
46+
<v-switch v-model="consent" color="primary" inset>
47+
<template v-slot:label>
48+
<i18n-t v-if="privacyPolicyUrl" keypath="authView.consent" scope="global" tag="p">
49+
<template v-slot:action>
50+
<a target="blank" :href="privacyPolicyUrl" @click.stop>
51+
{{ $t('authView.privacyPolicy') }}
52+
</a>
53+
</template>
54+
<template v-slot:newline><br /></template>
55+
</i18n-t>
56+
</template>
57+
</v-switch>
58+
</v-card-text>
59+
<v-btn color="primary" @click="signInOSM" :disabled="!consent" depressed>
60+
{{ $t('authView.signInOsm') }}
61+
</v-btn>
62+
</v-card>
63+
</template>
64+
</v-dialog>
65+
</template>
66+
67+
<style scoped></style>

src/components/SignUp.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import {
1010
import { getDatabase, ref, set } from 'firebase/database'
1111
import { logAnalyticsEvent } from '@/firebase'
1212
import { i18nRoute } from '@/i18n/translation'
13+
import SignInOsm from '@/components/SignInOsm.vue'
1314
1415
export default defineComponent({
16+
components: {
17+
signInOsm: SignInOsm,
18+
},
1519
data() {
1620
return {
1721
isFormValid: false,
@@ -186,6 +190,7 @@ export default defineComponent({
186190
{{ $t('authView.signUp') }}
187191
</v-btn>
188192
</v-col>
193+
<sign-in-osm />
189194
</v-form>
190195
</v-container>
191196
</template>

src/i18n/locales/de.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@
4141
"noAccountYet": "Du hast noch kein Konto?",
4242
"noUppercase": "Dein Nutzername darf keine Großbuchstaben enthalten.",
4343
"noSpace": "Dein Nutzername darf keine Leerzeichen enthalten.",
44+
"osmSignInSuccess": "Du bist mit OpenStreetMap angemeldet.",
45+
"osmSignInError": "Leider konnten wir dich nicht mit OpenStreetMap anmelden.",
46+
"or": "oder",
4447
"password": "Passwort",
4548
"passwordMatch": "Passwort stimmt nicht überein",
4649
"passwordResetEmailSent": "E-Mail zum Zurücksetzen des Passworts versandt",
4750
"privacyPolicy": "Datenschutzrichtlinie",
4851
"recoverAccount": "Konto wiederherstellen",
4952
"required": "Dies ist ein Pflichtfeld.",
5053
"signIn": "Anmelden",
54+
"signInOsm": "Mit OpenStreetMap anmelden",
55+
"signInOsmText": "Du kannst dich bei MapSwipe mit deinem OpenStreetMap-Konto anmelden. Wenn du bereits ein MapSwipe-Konto hast, werden die beiden Konten dadurch nicht miteinander verknüpft! (Diese Funktion wird in einer zukünftigen Version verfügbar sein.)",
5156
"signUp": "Registrieren",
5257
"signUpFailed": "Registrierung gescheitert"
5358
},

src/i18n/locales/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@
4141
"noAccountYet": "Don't have an account yet?",
4242
"noUppercase": "Your username cannot contain uppercase letters.",
4343
"noSpace": "Your username cannot contain space.",
44+
"osmSignInSuccess": "You are signed in with OpenStreetMap.",
45+
"osmSignInError": "Sorry, we did not manage to sign you in with OpenStreetMap.",
46+
"or": "or",
4447
"password": "Password",
4548
"passwordMatch": "Password does not match",
4649
"passwordResetEmailSent": "Password reset e-mail sent",
4750
"privacyPolicy": "Privacy Policy",
4851
"recoverAccount": "Recover account",
4952
"required": "This field is required.",
5053
"signIn": "Sign in",
54+
"signInOsm": "Sign in with OpenStreetMap",
55+
"signInOsmText": "You can sign in to MapSwipe using your OpenStreetMap account. If you already have a MapSwipe account, this will not link them together! (this will come soon in a future release)",
5156
"signUp": "Sign up",
5257
"signUpFailed": "Sign-up failed"
5358
},

src/i18n/locales/fr.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"auth/email-already-in-use": "E-mail déjà utilisé."
3131
},
3232
"confirmPassword": "Confirmer le mot de passe",
33-
"consent": "Je suis d'accord avec {action}.",
33+
"consent": "Je suis d'accord avec la {action}.",
3434
"consentSubtitle": "* Toutes vos contributions à MapSwipe sont en accès libres et disponibles pour tout le monde. Votre nom d'utilisateur est public mais votre e-mail et mot de passe ne seront jamais communiqués à des tiers.",
3535
"displayName": "Nom d'utilisateur",
3636
"email": "E-mail",
@@ -41,13 +41,18 @@
4141
"noAccountYet": "Pas encore de compte ?",
4242
"noUppercase": "Votre nom d'utilisateur ne peut pas contenir de lettres majuscules.",
4343
"noSpace": "Votre nom d'utilisateur ne peut pas contenir d'espaces.",
44+
"osmSignInSuccess": "Vous êtes connecté avec OpenStreetMap.",
45+
"osmSignInError": "Désolé, nous n'avons pas pu vous connecter avec OpenStreetMap.",
46+
"or": "ou",
4447
"password": "Mot de passe",
4548
"passwordMatch": "Le mot de passe ne correspond pas",
4649
"passwordResetEmailSent": "E-mail de réinitialisation de mot de passe envoyé",
4750
"privacyPolicy": "Politique de confidentialité",
4851
"recoverAccount": "Récupérer votre compte",
4952
"required": "Ce champ est obligatoire.",
5053
"signIn": "Se connecter",
54+
"signInOsm": "Se connecter avec OpenStreetMap",
55+
"signInOsmText": "Vous pouvez vous connecter à MapSwipe en utilisant votre compte OpenStreetMap. Si vous avez déjà un compte MapSwipe, cela ne les liera pas ensemble ! (Cette fonctionnalité sera disponible dans une future version.)",
5156
"signUp": "S'inscrire",
5257
"signUpFailed": "L'inscription a échoué"
5358
},

0 commit comments

Comments
 (0)