问题描述
我猜我的 vuejs 商店正在重置我的授权。我还在标头组件中收到错误消息 Cannot read property 'home' of undefined
。我不知道为什么这不起作用。我试过调试。
这是我所拥有的: 在我的 nuxt.config.js 中,我将插件设置为 firebase:
plugins: [
'~/plugins/firebase.js'
],
然后这是我的 firebase.js 文件:
import firebase from 'firebase/app'
import 'firebase/auth'
var firebaseConfig = {
apiKey: "MYAPIKEY",authDomain: "AUTHDOMAIN",databaseURL: "DBURL",projectId: "PROJECTID",storageBucket: "STORAGEBUCKET",messagingSenderId: "MESSAGINGSENDERID",appId: "APPID",measurementId: "MEASUREMENTID"
};
!firebase.apps.length ? firebase.initializeApp(firebaseConfig) : ''
export const auth = firebase.auth()
export default firebase
我不知道这是否与我的错误有关,但出于目的,我只是将其放入。
然后对于我的注册页面,我使用他们的 gmail 帐户注册用户,我在 methods
中有这样一个功能:
async registersocial() {
try {
const provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then((result) => {
this.account.email = result.user.email
this.account.naam = result.additionalUserInfo.profile.given_name
this.account.achternaam = result.additionalUserInfo.profile.family_name
this.$store.dispatch('users/registersocial',this.account).catch(err => {
this.errmsg = err
})
});
} catch(err) {
this.errmsg = err
}
}
这会触发商店注册用户设置cookie并将用户设置在商店中我这样做:
async registersocial({ commit },account) {
const token = await auth.currentUser.getIdToken();
const { email,uid } = auth.currentUser;
Cookie.set('access_token',token);
commit('SET_USER',{
email,uid
});
this.$router.push('profiel')
const users = firebase.database().ref('Gebruikers/')
users.once('value',function(snapshot){
const naam = account.naam
const achternaam = account.achternaam
const email = account.email
const google = "Google"
var sameemail = null
snapshot.forEach(function(childSnapshot) {
const data = childSnapshot.exportVal()
if(data.Email == email) {
sameemail = email
}
})
if(sameemail != email) {
users.push({
Voornaam: naam,Achternaam: achternaam,Email: email,registerMethod: google
})
}
})
}
然后对于我设置的 cookie,我这样做:
import JWTDecode from 'jwt-decode';
import cookieparser from 'cookieparser';
export const actions = {
nuxtServerInit({commit},{req}) {
if(process.server && process.static) return;
if(!req.headers.cookie) return;
const parsed = cookieparser.parse(req.headers.cookie);
const accesstokenCookie = parsed.access_token;
if(!accesstokenCookie) return;
const decoded = JWTDecode(accesstokenCookie);
if(decoded) {
commit('users/SET_USER',{
uid: decoded.user_id,email: decoded.email
})
}
}
}
请让我知道我做错了什么。如果您需要更多代码,请告诉我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)