Contents
前回の拙稿
https://maya-pg.net/2019/12/20/2019-12-20-150508/
この続き。
前回の前提、および経緯
・定数はConst.swiftに外出し
https://maya-pg.net/2019/12/20/2019-12-20-150508/
・Utility.debugLogはどこかからパクったんだけどデバッグウィンドウにファイル名称、行数込みで表示してくれる嬉しいfunction
・Const().actionCodeSettingsUrl = “https://hogehoge-ba123.firebaseio.com”←firebaseioとか聞いたことないドメインなので焦った
・self.showAlert()はAlert表示、およびその後の処理をまとめたもの
前回の前提の瑕疵
・Const().actionCodeSettingsUrl = “https://hogehoge-ba123.firebaseio.com”←firebaseioとか聞いたことないドメインなので焦った
https://hogehoge-ba123.firebaseio.com とか言うのを https://hogehoge-ba123.firebaseapp.comに読み替えてアクセス…404
これ勘違い。
節子、firebaseio.comはデータベースのURLや。
解決
firebase hostsにactionCodeSettings.urlのエンドポイントを作っていなければならなかったので→開発環境にあったファイルを配置。
で、よしなに https://hogehoge-ba123.firebaseapp.com を実装。
今回の現象
以下のコードの Utility.debugLog(errCode.rawValue ) が14行目で17999を返す
let actionCodeSettings = ActionCodeSettings()
actionCodeSettings.url = URL(string: Const().actionCodeSettingsUrl)
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
actionCodeSettings.setAndroidPackageName(Const().package_name,
installIfNotAvailable: false, minimumVersion: "12")
UserDefaults.standard.set(nil, forKey: "Email")
Auth.auth().sendSignInLink(
toEmail:email!,
actionCodeSettings: actionCodeSettings) { error in
if let error = error {
Utility.debugLog(error.localizedDescription)
if let errCode = AuthErrorCode(rawValue: error._code) {
Utility.debugLog(errCode.rawValue )
}
return
}
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
Utility.debugLog(email)
UserDefaults.standard.set(email!, forKey: "Email")
self.showAlert(alert_message:"登録メールアドレス宛に認証メールをお送り致しました。", flag: false)
}解決法
わかんねえんならわかんねえでいいからドキュメントくらいはちゃんと読め。という話でした。
https://firebase.google.com/docs/auth/ios/email-link-auth
Firebase Auth では、モバイルアプリで開かれるリンクを送信するときに Firebase Dynamic Links が使用されます。
https://firebase.google.com/docs/auth/ios/email-link-auth
Dynamic LinksのURL接頭辞をよしなに作成。hogehoge-ba123.page.linkとか提案されるのでそのまま作る。
ダイナミックリンクはなくてOK。
この hogehoge-ba123.page.link が認証メール内のドメインに適用され、こんなURLが認証メールに記述されます。
https://hogehoge-ba123.page.link/?link=https://hogehoge-ba123.firebaseapp.com/__/auth/action?apiKeyほにゃらら
これで幸せになれました。
さいごに
但し謎が残りました。
https://hogehoge-ba123.firebaseapp.com に配置している、認証メールの中継ページの元ネタですw
私のことだからどこかから拝借してる筈なんですがww