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) { export function metamaskLogin(data) {
return request({ return request({
url: '/user/metamask-login', url: '/user/metamask_login',
method: 'post', method: 'post',
data data
}) })
@ -35,4 +35,3 @@ export function getNonce(account) {
method: 'get' 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 { getToken, setToken, removeToken } from '@/utils/auth'
import router, { resetRouter } from '@/router' 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 // get user info
getInfo({ commit, state }) { getInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@ -18,7 +18,7 @@
<script> <script>
// import openWindow from '@/utils/open-window' // import openWindow from '@/utils/open-window'
import Web3 from 'web3' import Web3 from 'web3'
import { getNonce, metamaskLogin } from '@/api/user' import { getNonce } from '@/api/user'
export default { export default {
name: 'SocialSignin', name: 'SocialSignin',
@ -161,12 +161,14 @@ export default {
tips, tips,
net_id net_id
} }
metamaskLogin(authData).then(response => { this.$store.dispatch('user/metamaskLogin', authData)
this.$router.push({ path: this.redirect || '/', query: this.otherQuery }) .then(() => {
console.log(response) this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
}).catch((err) => { this.loading = false
console.log('Api getNonce Error:' + err) })
}) .catch(() => {
this.loading = false
})
}, },
async signData(signObj, signer) { async signData(signObj, signer) {
const msgParams = JSON.stringify(signObj) 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 // provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title. // it can be accessed in index.html to inject the correct title.
name: name, name: name,
devtool: 'source-map',
resolve: { resolve: {
alias: { alias: {
'@': resolve('src') '@': resolve('src')