Ajutor firebase verificare token actual cu token din mysql

<script>
const messaging = firebase.messaging();
messaging
        .requestPermission()
        .then(function () {
                console.log("Notification permission granted.");
           
                // get the token in the form of promise
                return messaging.getToken()

        })

        .then(function(token) {
		console.log(token);
        })
        .catch(function (err) {
                console.log("Unable to get permission to notify.", err);
        });
</script>

Vreau sa verific daca “token” este identic cu valoarea oferita de {$user->_fcm}

Am incercat ceva de genul

const messaging = firebase.messaging();
messaging
        .requestPermission()
        .then(function () {
                console.log("Notification permission granted.");
           
                // get the token in the form of promise
                return messaging.getToken()

        })

        .then(function(token) {
		console.log(token);

	if((token)=={$user->_fcm})
	{
		console.log("ok");

	}
	else
	{
		saveToken(token);
	}

        })
        .catch(function (err) {
                console.log("Unable to get permission to notify.", err);
        });

imi da eroarea Uncaught SyntaxError: Unexpected token ‘:’ in consola.

Ma poate ajuta cineva ?

Cred că amesteci php cu html în mod greșit. Presupunând că al doilea exemplu este un PHP care randează JS, poți face așa:

e.g.:

- if((token)=={$user->_fcm})
+ if((token)=="<?= $user->_fcm' ?>")

Dacă JS-ul nu e randat de PHP direct, ai nevoie de o altă modalitate de a trimite valori din PHP în JS.

if((token)=="{$user->_fcm}")

banuiesc ca aia-i o variabila de php.

Se poate inchide, am rezolvat
Trebuia sa pun " "

if((token) == "{$user->_fcm}")

Multumesc pentru ajutor

Mă indoiesc că ai rezolvat. În rezolvarea ta compari variabila “token” cu stringul “{$user->_fcm}”.

3 Likes