10000 Detect gunDB user already being created by yuetloo · Pull Request #543 · clrfund/monorepo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Detect gunDB user already being created #543

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

Merged
merged 1 commit into from
Aug 25, 2022
Merged
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
8 changes: 7 additions & 1 deletion vue-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ export default class App extends Vue {
if (!this.$web3.user) return

// Connect & auth to gun db
await this.$store.dispatch(LOGIN_USER, this.$web3.user)
try {
await this.$store.dispatch(LOGIN_USER, this.$web3.user)
} catch (error) {
/* eslint-disable-next-line no-console */
console.error(error)
return
}

this.$store.commit(SET_CURRENT_USER, this.$web3.user)
this.$store.dispatch(LOAD_USER_INFO)
Expand Down
15 changes: 10 additions & 5 deletions vue-app/src/api/gun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { gunPeers } from './core'
import { LOGIN_MESSAGE } from './user'
import { md5 } from '@/utils/crypto'

const GUN_WARNINGS = new Set([
'User already created!',
'User is already being created or authenticated!',
])

interface GunSchema {
data: { [key: string]: string }
}
Expand All @@ -26,19 +31,19 @@ export async function loginUser(
const password = encryptionKey
await new Promise((resolve, reject) => {
user.create(username, password, (ack) => {
if (ack.ok === 0 || ack.err === 'User already created!') {
resolve()
if (ack.ok === 0 || GUN_WARNINGS.has(ack.err)) {
resolve(0)
} else {
reject()
reject('Error creating user in GunDB.')
}
})
})
await new Promise((resolve, reject) => {
user.auth(username, password, (ack) => {
if (ack.err) {
reject()
reject('Error authenticating user in GunDB.')
} else {
resolve()
resolve(0)
}
})
})
Expand Down
0