Firebase Hostingを用い、React(ルーティングにはreact-router-domを使用)にてWEBアプリを公開しようとしています。basic認証を行いたいのですが、index.htmlを起点としたSPAなので、cloud functionsを通してルーティング処理をしようとしていますが、うまくいきません。
実装の内容としては以下リンクにあるような「basic-auth-connect」を用いたものです。
https://gist.github.com/mkamakura/c7a57bd1bf64b017f180573adf8ba3d8
json
1{ 2 "hosting": { 3 "public": "build", 4 "ignore": [ 5 "firebase.json", 6 "**/.*", 7 "**/node_modules/**" 8 ], 9 "redirects": [{ 10 "source": "/", 11 "destination": "/auth" 12 }], 13 "rewrites": [ 14 { 15 "source": "**", 16 "function": "app" 17 } 18 ] 19 } 20} 21
node
1const functions = require('firebase-functions') 2const express = require('express') 3const basicAuth = require('basic-auth-connect') 4 5const app = express() 6 7app.use(basicAuth('username', 'password')) 8 9app.get('/auth', (req, res) => { 10 res.redirect('/index.html') 11}) 12 13exports.app = functions.https.onRequest(app)
firebaseのfunctionsのコンソールからログを確認してみると、そもそもリダイレクトしてfunctionsの関数を通っていないようなのですが、ルーティング処理が上手くいないのは何が原因なのでしょうか。
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。