This commit is contained in:
azw 2024-07-13 18:42:53 +08:00
parent 41ee9ada74
commit 5bcefe2f27
4 changed files with 25 additions and 10 deletions

View File

@ -9,7 +9,7 @@ export function login(data) {
}
export function metamaskLogin(data) {
return request({
url: '/user/metamask-login',
url: '/user/metamask_login',
method: 'post',
data
})
@ -35,4 +35,3 @@ export function getNonce(account) {
method: 'get'
})
}

View File

@ -1,4 +1,4 @@
import { login, logout, getInfo } from '@/api/user'
import { login, logout, getInfo, metamaskLogin } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
import router, { resetRouter } from '@/router'
@ -44,6 +44,19 @@ const actions = {
})
},
metamaskLogin({ commit }, authData) {
return new Promise((resolve, reject) => {
metamaskLogin(authData).then(response => {
const { token } = response
commit('SET_TOKEN', token)
setToken(token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// get user info
getInfo({ commit, state }) {
return new Promise((resolve, reject) => {

View File

@ -18,7 +18,7 @@
<script>
// import openWindow from '@/utils/open-window'
import Web3 from 'web3'
import { getNonce, metamaskLogin } from '@/api/user'
import { getNonce } from '@/api/user'
export default {
name: 'SocialSignin',
@ -161,12 +161,14 @@ export default {
tips,
net_id
}
metamaskLogin(authData).then(response => {
this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
console.log(response)
}).catch((err) => {
console.log('Api getNonce Error:' + err)
})
this.$store.dispatch('user/metamaskLogin', authData)
.then(() => {
this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
this.loading = false
})
.catch(() => {
this.loading = false
})
},
async signData(signObj, signer) {
const msgParams = JSON.stringify(signObj)

View File

@ -42,6 +42,7 @@ module.exports = {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
name: name,
devtool: 'source-map',
resolve: {
alias: {
'@': resolve('src')