I'm trying to setup passwordless authentification in Firebase. I already enabled "email without password" auth in my Project settings. Using this documentation : https://firebase.google.com/docs/auth/admin/email-action-links#generate_email_link_for_sign-in I managed to implement a way to create auth links. My goal is to open https://dev.test.com/signup/ with the email of the user so he will be instantly signed in.
This is my code so far:
import firebase_admin
from firebase_admin import auth
def main():
default_app = firebase_admin.initialize_app()
email = 'name.chris@gmail.com'
action_code_settings = auth.ActionCodeSettings(
url=f'https://dev.test.com/signup/?email={email}',
handle_code_in_app=True,
ios_bundle_id='com.example.ios',
android_package_name='com.example.android',
android_install_app=True,
android_minimum_version='12',
dynamic_link_domain='magic42.page.link',
)
link = auth.generate_sign_in_with_email_link(email, action_code_settings)
print(f"LINK = {link}")
When I click on the link, I don't get automatically signed in. I guess I should also modify my front end. I'm using Angular. My signup looks like this :
signUp(email: string, password: string): Observable<UserCredential> {
const credential = firebase.auth.EmailAuthProvider.credential(email, password);
return from(firebase.auth().currentUser.linkWithCredential(credential));
}
I'm confused why you have email and password on frontend. To complete sign in using the email link, you should be using firebase.auth().signInWithEmailLink()
method and not linkWithCredential on your /signup page.
You can get sample code (which should be executed on your /signup page) of completing sign in with email link in the documentation: https://firebase.google.com/docs/auth/web/email-link-auth