Disable password login if registration is token-gated

This commit is contained in:
silverpill 2022-11-16 19:08:58 +00:00
parent a9643a2425
commit f261839c59
2 changed files with 25 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import { BACKEND_URL } from "@/constants"
import { http } from "./common" import { http } from "./common"
interface Features { interface Features {
gate: boolean;
minter: boolean; minter: boolean;
subscriptions: boolean; subscriptions: boolean;
} }

View file

@ -12,6 +12,7 @@
<div v-if="instance" class="login-form-group"> <div v-if="instance" class="login-form-group">
<div class="login-type"> <div class="login-type">
<button <button
v-if="!isWalletRequired()"
:class="{ active: loginType === 'password' }" :class="{ active: loginType === 'password' }"
@click.prevent="loginType = 'password'; loginErrorMessage = null" @click.prevent="loginType = 'password'; loginErrorMessage = null"
> >
@ -94,7 +95,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { $, $ref } from "vue/macros" import { watch } from "vue"
import { $, $$, $ref } from "vue/macros"
import { useRouter } from "vue-router" import { useRouter } from "vue-router"
import { import {
@ -116,13 +118,29 @@ const { setCurrentUser, setAuthToken } = useCurrentUser()
const { instance } = $(useInstanceInfo()) const { instance } = $(useInstanceInfo())
const isRegistered = $ref(true) const isRegistered = $ref(true)
const loginType = $ref<"password" | "eip4361">(hasEthereumWallet() ? "eip4361" : "password")
const username = $ref("") const username = $ref("")
const password = $ref<string | null>(null) const password = $ref<string | null>(null)
const inviteCode = $ref<string | null>(null) const inviteCode = $ref<string | null>(null)
let loginType = $ref<"password" | "eip4361">("password")
let isLoading = $ref(false) let isLoading = $ref(false)
let loginErrorMessage = $ref<string | null>(null) let loginErrorMessage = $ref<string | null>(null)
function isWalletRequired(): boolean {
if (!instance) {
return false
}
const blockchain = instance?.blockchains[0]
return Boolean(blockchain?.features.gate)
}
watch($$(instance), () => {
if (hasEthereumWallet() || isWalletRequired()) {
// Switch to EIP-4361 if wallet is present or
// if registration is token-gated
loginType = "eip4361"
}
}, { immediate: true })
function isLoginFormValid(): boolean { function isLoginFormValid(): boolean {
if (!instance) { if (!instance) {
return false return false
@ -315,11 +333,13 @@ $text-color: #fff;
width: 100%; width: 100%;
&:first-child { &:first-child {
border-radius: 10px 0 0 10px; border-bottom-left-radius: 10px;
border-top-left-radius: 10px;
} }
&:last-child { &:last-child {
border-radius: 0 10px 10px 0; border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
} }
&.active { &.active {