Skip to content

Commit

Permalink
Fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil committed May 31, 2024
1 parent 708be5d commit ee84081
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
14 changes: 12 additions & 2 deletions src/components/NearLogin.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<wallet-ctx-provider-vue network="testnet">
<near-login-vue
appId="4a69641790ae9b710c29ee99edb2c8560812e7752bb392cdf001ee0002fa4647"
rpcBaseUrl="http://localhost:2528"
:appId="appId"
:rpcBaseUrl="rpcBaseUrl"
:successRedirect="success"
:navigateBack="auth"
>
Expand All @@ -23,6 +23,16 @@ export default {
WalletCtxProviderVue: applyPureReactInVue(WalletSelectorContextProvider),
NearLoginVue: applyPureReactInVue(NearLogin)
},
props: {
appId: {
type: String,
required: true
},
rpcBaseUrl: {
type: String,
required: true
}
},
setup() {
const router = useRouter()
function success() {
Expand Down
22 changes: 20 additions & 2 deletions src/components/PlayGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
v-model="applicationId"
class="q-mr-xs bg-white"
/>
<div class="row q-pa-sm">
<div class="row q-mt-sm">
<q-input dense outlined label="Node URL" v-model="nodeUrl" class="col q-mr-xs bg-white" />
<q-btn color="primary" flat no-caps class="q-mr-xs" @click="connectToNode">Connect</q-btn>
<q-btn
v-if="isAuthenticated()"
color="primary"
flat
no-caps
class="q-mr-xs"
@click="connectToNode"
>Connect</q-btn
>
<q-btn v-else color="orange" no-caps class="q-mr-xs" @click="navigateToLoginPage"
>Login</q-btn
>
</div>
<q-separator />
<div class="q-ml-md row items-center justify-center">
Expand Down Expand Up @@ -78,6 +89,8 @@
import { ref } from 'vue'
import { Game } from '../game'
import GameEventListener from '../ws'
import { isAuthenticated } from '../auth'
import { useRouter } from 'vue-router'
const nodeUrl = ref('http://localhost:2428')
const applicationId = ref('4a69641790ae9b710c29ee99edb2c8560812e7752bb392cdf001ee0002fa4647')
Expand All @@ -91,6 +104,7 @@ const opponentCommited = ref(false)
const opponentRevealed = ref(false)
const players = ref({})
const winnerIdx = ref(null)
const router = useRouter()
const connectToNode = async () => {
game = new Game(nodeUrl.value, applicationId.value)
Expand Down Expand Up @@ -155,4 +169,8 @@ const reveal = async () => {
console.log(error)
}
}
const navigateToLoginPage = () => {
router.push({ name: 'login', query: { appId: applicationId.value, rpcUrl: nodeUrl.value } })
}
</script>
6 changes: 1 addition & 5 deletions src/pages/IndexPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
class="row bg-grey-1 items-center justify-center"
style="width: 900px; border: 1px solid #ababab; border-radius: 2px"
>
<play-game v-if="isAuthenticated()" />
<div v-else class="col row justify-center">
<q-btn dense no-caps to="/login" color="orange-8" size="xl">Login</q-btn>
</div>
<play-game />
<q-separator vertical />
<div class="col">
<leader-board />
Expand All @@ -19,7 +16,6 @@
<script setup>
import LeaderBoard from '../components/LeaderBoard.vue'
import PlayGame from '../components/PlayGame.vue'
import { isAuthenticated } from '../auth'
defineOptions({
name: 'IndexPage'
Expand Down
4 changes: 2 additions & 2 deletions src/pages/LoginPage.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup>
import NearLogin from "../components/NearLogin.vue";
import NearLogin from '../components/NearLogin.vue'
</script>

<template>
<main>
<NearLogin />
<NearLogin :appId="$route.query.appId" :rpcBaseUrl="$route.query.rpcUrl" />
</main>
</template>

0 comments on commit ee84081

Please sign in to comment.