当我单击登录按钮时,出现此错误:
[19:49:11] [2018-12-25T20:49:57.389Z] @firebase/database:, FIREBASE
FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR
FIREBASE>.firebaseio.com
- node_modules/@firebase/logger/dist/index.cjs.js:69:32 in
defaultLogHandler
- node_modules/@firebase/logger/dist/index.cjs.js:159:31 in error
- node_modules/@firebase/database/dist/index.cjs.js:333:20 in fatal
- node_modules/@firebase/database/dist/index.cjs.js:1256:14 in
parseRepoInfo
- node_modules/@firebase/database/dist/index.cjs.js:15103:38 in
refFromURL
* src/modules/auth/api.js:24:24 in getUser
* src/modules/auth/api.js:19:32 in <unknown>
- node_modules/@firebase/auth/dist/auth.js:17:105 in <unknown>
- node_modules/@firebase/auth/dist/auth.js:20:199 in Fb
- ... 13 more stack frames from framework internals
我直接从Firebase复制并粘贴了配置内容,因此它应该是正确的,但是无论如何我都会遇到此错误。是什么原因造成的?我从数据库复制的URL可能以某种方式是错误的吗?
您可以在显示的错误中看到
在我的文件api.js中.then((user) => getUser(user, callback))
和
database.refFromURL('users').child(user.uid).once('value')
这是我来自api.js的代码,如下所示:
import { auth, database, provider } from "../../config/firebase";
export function register(data, callback) {
const { email, password } = data;
auth.createUserWithEmailAndPassword(email, password)
.then((user) => callback(true, user, null))
.catch((error) => callback(false, null, error));
}
export function createUser (user, callback) {
database.refFromURL('users').child(user.uid).update({ ...user })
.then(() => callback(true, null, null))
.catch((error) => callback(false, null, {message: error}));
}
export function login(data, callback) {
const { email, password } = data;
auth.signInWithEmailAndPassword(email, password)
.then((user) => getUser(user, callback))
.catch((error) => callback(false, null, error));
}
export function getUser(user, callback) {
database.refFromURL('users').child(user.uid).once('value')
.then(function(snapshot) {
const exists = (snapshot.val() !== null);
if (exists) user = snapshot.val();
const data = { exists, user }
callback(true, data, null);
})
.catch(error => callback(false, null, error));
}
任何人都可以帮助我错过的地方
答案 0 :(得分:1)
我用过
database.ref(`users/`+user.uid).once('value')
代替
database.refFromURL('users').child(user.uid).once('value')
现在对我来说很好。
答案 1 :(得分:0)
refFromURL
方法需要数据库的完全限定URL。因此,错误消息显示的内容以https://<YOUR
FIREBASE>.firebaseio.com
开头。
您正在尝试访问已配置数据库中的路径,在这种情况下,应改用ref(...)
:
database.ref('users').child(user.uid).once('value')