2

Below is the error I get. I watched a tutorial and the developer had the exact same code and it worked on his end, I don't know what I'm doing wrong. I am using the getstream.io platform through the stream_chat_flutter_core package.

Response is not valid JSON object.
I/flutter ( 8805): 
I/flutter ( 8805): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
I/flutter ( 8805): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:49:37)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #4      FirebaseService.joinWithEmailAndPassword (package:thrills/util/firebase_service.dart:357:25)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #5      _JoinState.build.<anonymous closure> (package:thrills/screens/join/join.dart:285:33)
I/flutter ( 8805): <asynchronous suspension>

Below is the cloud function I use in firebase

const StreamChat = require('stream-chat').StreamChat;
const functions = require("firebase-functions");
const admin = require("firebase-admin");

admin.initializeApp();

const serverClient = StreamChat.getInstance(functions.config().stream.key, functions.config().stream.secret);

exports.createStreamUserAndGetToken = functions.region("us-west2").https.onCall(async (data, context) => {
  // Checking that the user is authenticated.
  if (!context.auth) {
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
      'while authenticated.');
  } else {
    try {
      // Create user using the serverClient.
      await serverClient.upsertUser({
        id: context.auth.uid,
        name: context.auth.token.name,
        email: context.auth.token.email,
        image: context.auth.token.image,
      });

      // Create and return user auth token.
      return serverClient.createToken(context.auth.uid);
    } catch (err) {
      console.error(`Unable to create user with ID ${context.auth.uid} on Stream. Error ${err}`);
      // Throwing an HttpsError so that the client gets the error details.
      throw new functions.https.HttpsError('aborted', "Could not create Stream user");
    }
  }
});

And finally, here is how I am calling the function and retrieving the data

final callable = FirebaseFunctions.instance
            .httpsCallable('createStreamUserAndGetToken');
final results = await callable();
some random code... (results.data is only used once as an argument to some function)
results.data as String       
ClarenceHD
  • 139
  • 1
  • 11

0 Answers0