'Firebase token not generated in flutter web

Error:

[firebase_messaging/token-subscribe-failed] Messaging: A problem occurred while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. .

at Object.createErrorWithStack (http://localhost:2277/dart_sdk.js:5080:12)
at Function._throw (http://localhost:2277/dart_sdk.js:20337:18)
at Function.throwWithStackTrace (http://localhost:2277/dart_sdk.js:20334:18)
at async._AsyncCallbackEntry.new.callback (http://localhost:2277/dart_sdk.js:40851:18)
at Object._microtaskLoop (http://localhost:2277/dart_sdk.js:40708:13)
at _startMicrotaskLoop (http://localhost:2277/dart_sdk.js:40714:13)
at http://localhost:2277/dart_sdk.js:36191:9



Solution 1:[1]

You are mapping the movies variable, but the sorted array is stored on the movieList state

This should work

...
{movieList.map((movie) => (
...

Solution 2:[2]

I tried as your idea. But no problem in my app. This made me clearly. Then, I suggest two points.

  1. Once confirm your movieList obj at the first of sortByTitle function.
  2. Another confirm top-down flow data 'movies' : type.
  3. From there, 'sorted' is a array, 'movieList' seems like a object. Just this is important. I tell you this.

Carefully, be attention.

Solution 3:[3]

  const sortByTitle = () => {
    const sorted = [
      ...movieList.sort((a, b) => {
        return a.title.localeCompare(b.title);
      })
    ];
    setMovieList(sorted);
  };

That is the required code. Compare above code with your code and you'll find that you are not retuning a new array.

sort method sorts the array in place READ HERE but it doesn't return a new array(i.e., returns reference of old array). And react needs a new array in order to detect any change in the state and you can do it by providing it a new array like I did in above code.

For proof: Check this codesandbox

Thanks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabriel Nuñez de Andrade
Solution 2
Solution 3 Sahil Rajput