当我点击登录按钮时,我得到这个错误:
[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));
}
有人能帮我弥补一下吗
3条答案
按热度按时间lyr7nygr1#
refFromURL
方法需要一个指向数据库的完全限定的URL,因此错误消息显示的是以https://<YOUR FIREBASE>.firebaseio.com
开头的URL。您正在尝试访问已配置数据库中的路径,在这种情况下,您应该改用
ref(...)
:cuxqih212#
请仔细阅读本文档并更新为新的模块化类型,或者如果要使用旧结构,请更新为
全部更新到8.5.0版。将完美工作
7ajki6be3#
我使用
而不是
现在对我来说效果很好。