angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Setting auth.languageCode is impossible due to PromiseProxy.

Open kertof opened this issue 6 years ago • 5 comments

This issue comes from the PromiseProxy and the fact that languageCode is both a getter and setter.

Version info

Angular: "@angular/core": "~10.1.4", Firebase: "firebase": "^7.19.1", AngularFire: "@angular/fire": "^6.0.2",

How to reproduce these conditions

// Try to change AngularFIreAuth languageCode
this.fireAuth.languageCode = 'fr';
// This fails because "Type 'string' is not assignable to type 'Promise<string>'."
// This comes from the PromiseProxy and the fact that languageCode is both a getter and setter.

// Setting to a Promise doesn't have any effect.
this.fireAuth.languageCode = new Promise(() => 'fr');

Expected behavior

I should be able to change the languageCode of the auth Object, to send email action templates in the user's language.

Actual behavior

The languageCode property doesn't work with the PromiseProxy. All email action templates are sent with the default Firebase Console language setting.

kertof avatar Oct 06 '20 13:10 kertof

I'm aiming to support language code in 6.1, hopefully should have the time to take a pass shortly

jamesdaniels avatar Oct 16 '20 17:10 jamesdaniels

Fantastic!

As a current workaround, I use firebase directly, with a delay, to make sure the app is initialized by AngularFire first.

import * as firebase from 'firebase/app';
import 'firebase/auth';

firebase.auth().languageCode = langCode;

kertof avatar Oct 19 '20 09:10 kertof

6.1.0-rc.2 now has USE_DEVICE_LANGUAGE and LANGUAGE_CODE DI tokens which allow configuration of the auth language.

jamesdaniels avatar Nov 13 '20 01:11 jamesdaniels

With:

  • Angular ^12.2.0
  • Firebase ^8.10.0
  • AngularFire ^6.1.5

setting LANGUAGE_CODE DI token value does not impact email language.

Value of languageCode stored in AngularFireAuth service equals the one provided with DI token.

import { AngularFireAuth } from '@angular/fire/auth';

  constructor(
    private authService: AngularFireAuth,
  ) {
    this.authService.languageCode.then((languageCode) =>
      console.log(languageCode) // will print a value provided with DI token, e.g. "pl"
    );
  }

but emails are still sent in the default language.

Must still use firebase.auth() directly to change email language:

import * as firebase from 'firebase/app';
import 'firebase/auth';

firebase.auth().languageCode ='pl'; // emails will be sent in provided language

bartosz-kepka avatar Oct 29 '21 22:10 bartosz-kepka

I am still facing this issue... this.afAuth.languageCode = Promise.resolve(lang); still sends emails with default template language set in firebase console. Screenshot 2022-11-30 at 11 15 18

import * as firebase from 'firebase/app';
import 'firebase/auth';

firebase.auth().languageCode ='pl'; // emails will be sent in provided language

this workaround does not work because auth() does not exsists in firebase..

any solution anyone?

vytautas-pranskunas- avatar Nov 30 '22 10:11 vytautas-pranskunas-