2016-08-07 2 views
2

Firebase v2를 사용하는 대형 SPA가 있습니다. 새 API로 업그레이드하고 싶지만 다음과 같은 문제가 발생합니다.Firebase - Node.js 서버에 사용자 생성

앱이 상당히 크기 때문에 많은 통합 테스트를 개발했으며 이러한 테스트를 위해 항상 데이터베이스를 재설정하고 초기화해야합니다. 일부 사용자가있는 상태 그러나 더 이상 서버에 사용자를 생성하는 것과 같은 것이 없다는 것을 알았습니다. (Firebase createUserWithEmailAndPassword method is undefined in node.js) API를 업그레이드하는 방법과 서버에서 데이터베이스를 초기화하고 초기화 할 수있는 방법이 확실하지 않습니다.

또한 우리는 Firebase v2가 여전히 Facebook OAuth 용으로 폐기 된 Graph API v2.0을 사용하고 있으며 8.8.2016 이후에 사용하도록 권장되지 않았기 때문에이 업그레이드를 수행해야합니다. Firebase v2는 v2가 기존 버전이므로 그래프 API에 대한 호출을 업그레이드하지 않을 것입니다. 그러나 이것은 우리를 지금 당황하게하고 있습니다.

이 주제에 대한 도움이 필요하십니까?

답변

4

Firebase v3.3.0부터 Node를 사용하여 사용자 계정을 만들 수 있지만이 방법을 공개하는 방법에 대한 문서는별로 좋지 않습니다.

사용자 관리 방법을 사용하려면 웹 API 키를 사용하여 노드의 응용 프로그램을 초기화해야하며 설치 안내서에있는 서비스 계정 구성은 초기화하지 않아야합니다.

// The Usual Service Account Init 
// This will not contain any user management methods on firebase.auth() 
this.app = firebase.initializeApp(
    { 
    serviceAccount: 'path/to/serviceaccount/file.json', 
    databaseURL: 'https://mydbfb.firebaseio.com' 
    }, 
    'MyAppName'); 

// Web Client Init in Node.js 
// firebase.auth() will now contain user management methods 
this.app = firebase.initializeApp(
    { 
    "apiKey": "my-api-key", 
    "authDomain": "somedomain.firebaseapp.com", 
    "databaseURL": "https://mydbfb.firebaseio.com", 
    "storageBucket": "myfbdb.appspot.com", 
    "messagingSenderId": "SomeId" 
    }, 
    'MyAppName'); 

당신은 웹 설치 가이드 https://firebase.google.com/docs/web/setup

이 내가 명시 적으로 얻을 API 키를 초기화하기 위해서 필요를 참조하는 찾을 수있는 유일한 기준이다에서 중포 기지 콘솔에서 클라이언트 API 키를 잡을 수 있습니다 일하다. 아래 https://groups.google.com/forum/#!msg/firebase-talk/_6Rhro3zBbk/u8hB1oVRCgAJ

1

은 다음 블로그 게시물을

http://navraj.net/?p=53

감사

을 볼 수 있습니다 자세한 내용은 Node.js를

exports.addUser = function(req, res) { 
var wine = req.body; 

var email = req.body.email; 
console.log(req.body); 
var password = req.body.password; 
var name = req.body.name; 

console.log(“Creating user for -“+email+”-“+password); 

var defaultAuth = admin.auth(); 
admin.auth().createUser({ 
email: email, 
emailVerified: false, 
password: password, 
displayName: name, 
disabled: false 
}) 
.then(function(userRecord) { 

console.log(“Created Firebase User successfully with id :”, userRecord.uid); 
var wine = req.body; 
wine.userId = userRecord.uid; 
wine.timestamp = Date.now(); 
delete wine.password; 
status = “201”; 
var reply = JSON.stringify(wine); 

db.collection(‘collname’, function(err, collection) { 
collection.insert(wine, {safe:true}, function(err, result) { 
if (err) { 
wine.status = “200”; 
wine.message = “An error occured”; 
reply.set(‘status’,”201″); 
res.status(201).send(wine); 

} else { 
console.log(‘Success: ‘ + JSON.stringify(result[0])); 
status= “200”; 
wine.status = “200”; 
wine.message = “Account created Successfully”; 
res.status(200).send(wine); 
} 
}); 
}); 
}) 
.catch(function(error) { 
wine.message = “An error occured—“; 
wine.status = “201”; 

console.log(“User Creation onf Firebase failed:”, error); 
res.status(201).send(wine); 
}); 

} 

통해 중포 기지 사용자를 만드는 작업 예입니다