Skip to content

Commit

Permalink
feat: allow unverified users (configurable)
Browse files Browse the repository at this point in the history
Adds an env variable VITE_ALLOW_UNVERIFIED_USERS. If true, unverified users may access projects
and contribute.
  • Loading branch information
ofr1tz committed Apr 25, 2024
1 parent 7426b27 commit 89e8757
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ VITE_PRIVACY_POLICY_URL='https://mapswipe.org/{locale}/privacy/'
VITE_IMPRINT_URL=
VITE_APP_LOGO='./img/mapswipe-white.svg'
VITE_PROJECTS_FALLBACK_IMAGE="./img/map-pin-600x400.jpg"
VITE_ALLOW_UNVERIFIED_USERS=true

# Locales
VITE_DEFAULT_LOCALE=en
Expand Down
6 changes: 5 additions & 1 deletion src/components/AppBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ export default defineComponent({
isVerified() {
return this.currentUserStore.currentUser?.emailVerified
},
allowUnverifiedUsers() {
const allow = import.meta.env.VITE_ALLOW_UNVERIFIED_USERS
return allow
},
},
})
</script>

<template>
<v-banner v-if="user && !isVerified" bg-color="accent" density="compact">
<v-banner v-if="user && !isVerified && !allowUnverifiedUsers" bg-color="accent" density="compact">
<v-banner-text>
<h4>{{ $t('appBanner.title') }}</h4>
<p>{{ $t('appBanner.message') }}</p>
Expand Down
6 changes: 5 additions & 1 deletion src/components/SignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default defineComponent({
currentLocale() {
return this.$i18n.locale
},
allowUnverifiedUsers() {
const allow = import.meta.env.VITE_ALLOW_UNVERIFIED_USERS
return allow
},
},
methods: {
i18nRoute,
Expand All @@ -45,7 +49,7 @@ export default defineComponent({
signInWithEmailAndPassword(auth, this.email, this.password)
.then((userCredential) => {
const user = userCredential.user
if (user.emailVerified) {
if (user.emailVerified || this.allowUnverifiedUsers) {
routerPush(i18nRoute({ name: 'projects' }))
} else {
routerPush(
Expand Down
18 changes: 15 additions & 3 deletions src/components/SignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ export default defineComponent({
const locale = this.$i18n.locale
return url.replace('{locale}', locale)
},
allowUnverifiedUsers() {
const allow = import.meta.env.VITE_ALLOW_UNVERIFIED_USERS
return allow
},
},
methods: {
signup() {
if (this.isFormValid && this.consent) {
const auth = getAuth()
const db = getDatabase()
const routerPush = this.$router.push
createUserWithEmailAndPassword(auth, this.email, this.password)
.then((userCredential) => {
Expand Down Expand Up @@ -89,9 +94,16 @@ export default defineComponent({
})
.then(() => {
logAnalyticsEvent('account_created')
this.$router.push(
i18nRoute({ name: 'authentication', params: { authTab: 'recover-account' } }),
)
if (this.allowUnverifiedUsers) {
routerPush(i18nRoute({ name: 'projects' }))
} else {
routerPush(
i18nRoute({
name: 'authentication',
params: { authTab: 'recover-account' },
}),
)
}
this.showSnackbar(this.$t('authView.followInstructionOnYourEmail'), 'info')
})
.catch((error) => {
Expand Down
3 changes: 2 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { getCurrentUser } from 'vuefire'
import { default as Tr, i18nRoute } from '@/i18n/translation'

const appName = import.meta.env.VITE_APP_NAME
const allowUnverifiedUsers = import.meta.env.VITE_ALLOW_UNVERIFIED_USERS

const denyUnauthorized = async (to, from, next) => {
const currentUser = await getCurrentUser()
if (currentUser?.emailVerified) {
if (currentUser?.emailVerified || (currentUser && allowUnverifiedUsers)) {
next()
} else if (currentUser) {
next(i18nRoute({ name: 'home', params: { authTab: 'recover-account' } }))
Expand Down

0 comments on commit 89e8757

Please sign in to comment.