node.js / firebase関数が自分のWebサイト「www.website.com/auth/**」で正常にホストされています。
このコードは、パスワードやメールの確認などをリセットするためのカスタムメールハンドラーです。
現時点では、oobCodeが有効かどうかを確認し、コードで指定された電子メールをユーザーに返して実験するだけです。関数ログでエラーが発生し続けます。
auth.verifyPasswordResetCode is not a function at resetPassword (/srv/index.js:51:8)
これは、Firebaseプロジェクトでホストされているサーバーコードです。
const express = require('express');
const admin = require('firebase-admin');
const functions = require('firebase-functions')
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://clipify-1b5ce.firebaseio.com"
});
const auth = admin.auth();
const app = express();
app.get('/', (req, res) => {
res.send('Website in progress...');
});
app.get('/auth/**', (request, response) => {
// Get the action to complete.
var mode = request.query.mode;
// Get the one time code to authenticate.
var actionCode = request.query.oobCode;
// (Optional) Get the contine URL .
var continueURL = request.query.continueURL;
// (Optional) Get the language code.
var lang = request.query.lang;
// What mode is it?
switch (mode){
case 'resetPassword':
// Reset password - display UI and init backend code.
response.send(resetPassword(actionCode, continueURL, lang));
break;
case 'recoverEmail':
// Recover email - display UI and init backend code.
//recoverEmail(auth, actionCode, lang);
break;
case 'verifyEmail':
// Verify email - display UI and init backend code.
//verifyEmail(auth, actionCode, continueURL, lang);
break;
default:
//response.send('Error')
response.send("Internal server error - no API token.")
}
});
function resetPassword(actionCode, continueURL, lang){
auth.verifyPasswordResetCode(actionCode).then(function(email) {
var accountEmail = email;
return accountEmail
}).catch(function(error){
return error
});
}
exports.app = functions.https.onRequest(app);
実際、クラウド関数では、「Firebaseサービスを使用するアプリケーションで使用されるクライアント側ライブラリを実装する」JavaScript SDKではなく、Firebase Admin Node.jsSDKを使用します。
verifyPasswordResetCode()
Admin Node.js SDK Authサービスのメソッドではなく、JavaScriptSDKのメソッドであるAdminNode.jsSDKリファレンスに表示されます。
その理由は、「ワンタイムコード」を送信し、このコードを使用してパスワードを更新するワークフローは、バックエンドのクラウド機能ではなく、フロントエンドで発生する必要があるためです。
簡単に言うと、フロントエンド(アプリ内)でユーザーが受け取ったコードを確認し、コードが有効な場合は、ユーザーをフォームにリダイレクトして、新しいパスワードを入力します。検証済みのコードと一緒に使用して、confirmPasswordReset()
メソッドを呼び出します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加