2016-06-27 7 views
5

firebaseを使用した電子メールの確認が固まっています。私はガイダンスのために見てきましたが、助けはありません。ユーザーが電子メールを確認した後も、自分のコードではまだユーザーが確認されていないことが表示されます。私はまだfirebaseの構文に慣れようとしています。ここに私のコードは次のとおりです。ここiOSでFirebaseを使用してユーザーのメールアドレスを確認するにはどうすればよいですか?

if FIRAuth.auth()?.currentUser!.emailVerified == true{ 
    FIRAuth.auth()?.signInWithEmail(email.text!, password: passsword.text!, completion: { 
     user, error in 

     if error != nil{ 
      print("Email/password is wrong or user does not exist") 
     }else{ 
      print("Successful login.") 
     } 
    }) 
}else{ 
    print("Please verify your email.") 
} 

は、サインアップセクションのための私のコードは次のとおりです。

let eduEmail = email.text 
    let endInEdu = eduEmail?.hasSuffix("my.utsa.edu") 

    if endInEdu == true { 

     FIRAuth.auth()?.createUserWithEmail(email.text!, password: passsword.text!, completion: { 
      user, error in 

      if error != nil{ 
       let alert = UIAlertController(title: "User exists.", message: "Please use another email or sign in.", preferredStyle: UIAlertControllerStyle.Alert) 
       alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)) 
       self.presentViewController(alert, animated: true, completion: nil) 

       print("Email has been used, try a different one") 
       }else{ 

FIRAuth.auth()?.currentUser!.sendEmailVerificationWithCompletion({ (error) in 
         }) 


       let alert = UIAlertController(title: "Account Created", message: "Please verify your email by confirming the sent link.", preferredStyle: UIAlertControllerStyle.Alert) 
       alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)) 
       self.presentViewController(alert, animated: true, completion: nil) 








       print("This is a college email and user is created") 




      } 


     }) 


    }else{ 
     print("This is not a my.utsa.edu email") 
     } 
+1

ちょっとイエス!ようこそstackoverflowへ。よりわかりやすい質問タイトルを設定することを強くお勧めします。 – adolfosrs

+0

現在のユーザーでsendEmailVerificationを呼び出して、メールで送信された電子メールの確認リンクをクリックしていますか? – bojeil

+0

はい私はそうです。サインアップビューのコントローラファイルにあります。サインアップすると、アカウントが作成されたときに電子メールが自動的に送信されます。 – jesusnieto5413

答えて

1

あなたはFIRAuth.auth()がnilだった場合は、次のメソッド呼び出しはnilを返します意味FIRAuth.auth()後合体演算子を使用しています。この場合、trueとの比較は、niltrueではないため、失敗します。

は、私はあなたが簡単にデバッグのために、このようなあなたのコードをリファクタリングすることをお勧め:

guard let auth = FIRAuth.auth(), user = auth.currentUser else { 
    print("No auth/user") 
} 

guard user.emailVerified else { 
    print("Email not verified") 
    return 
} 

guard let email = email.text, password = passsword.text else { 
    print("No email or password") 
    return 
} 

auth.signInWithEmail(email, password: password) { user, error in 
    if let error = error { 
     print("Email/password is wrong or user does not exist, error: \(error)") 
    } else { 
     print("Successful login.") 
    } 
} 

あなたは簡単にこのようなあなたのエラーを見つける必要があります。

+0

電子メールを確認した後も同じ "電子メールが検証されません"。 – jesusnieto5413

+0

@ jesusnieto5413さて、Firebase側で何かが間違ってしまったのですが、それ以上にお手伝いできません。 – Kametrixom

+0

@ jesusnieto5413あなたは解決策を見つけましたか? 、 私は同じ問題を抱えています。私は検証を行いますが、isEmailVerifiedはFalseを返します。 – EhsanR

9

ユーザーの電子メールをしても、それらに署名する前に確認された場合は、チェックを。

をこれは私のために働いたものです。

FIRAuth.auth()?.signInWithEmail(txtUsername.text!, password: txtPassword.text!) { 
     (user, error) in 
     if let user = FIRAuth.auth()?.currentUser { 
      if !user.emailVerified{ 
       let alertVC = UIAlertController(title: "Error", message: "Sorry. Your email address has not yet been verified. Do you want us to send another verification email to \(self.txtUsername.text).", preferredStyle: .Alert) 
       let alertActionOkay = UIAlertAction(title: "Okay", style: .Default) { 
        (_) in 
         user.sendEmailVerificationWithCompletion(nil) 
       } 
       let alertActionCancel = UIAlertAction(title: "Cancel", style: .Default, handler: nil) 

       alertVC.addAction(alertActionOkay) 
       alertVC.addAction(alertActionCancel) 
       self.presentViewController(alertVC, animated: true, completion: nil) 
      } else { 
       print ("Email verified. Signing in...") 
      } 
     } 
    } 
+0

ありがとうございました –

関連する問題