FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
114 stars 19 forks source link

Google Cloud JWT Token error #3395

Closed frito-pibble closed 1 month ago

frito-pibble commented 1 month ago

Can we access your project?

Current Behavior

When calling a google cloud function and passing in a JWT Token for authentication, there is an error on the server "SyntaxError: Unexpected token '}', ..."atform": ". This started occurring Thursday CST after updating to latest FlutterFlow desktop version. Two reason I believe there is a bug in FlutterFlow. 1 ) All functions call via Postman, passing in JWT Token are working. 2) There are two environments local and googel cloud. The google cloud environment has not been update in over a week and no changes to the FlutterFlow for these api calls. Function calls from client to either localhost or Google Cloud produce the same error.

Expected Behavior

The cloud function should parse the token and verify but it seems to running to a format issue.

Steps to Reproduce

  1. create a new FlutterFlow project with Firebase auth
  2. create simple cloud function that also verifies jwt token
  3. add api call to function, pass in authenticated user jwt token

Reproducible from Blank

Bug Report Code (Required)

IT4sjMmAx41gocdG0b6JacdB/T0QJUR7ao0wscsZa0kdB4joPLJ/evfSbVVvQu7gT2lhHFr++X803PD7kYbDFcE3Ok+sf49y+sxQawnMc3q8RcmXEpaoSHBSHcZUJh2n1quzoCNCBMtsR3cs2l+UDdzJbBbsCZO/Zwh9f6PHaOI=

Visual documentation

image image

Environment

- FlutterFlow version: 4.1.72
- Platform: web, iOS and Android simulators
- Browser name and version: chrome Version 126.0.6478.127 (Official Build) (arm64); iOS Simulator: Version 15.4 (1019.2)
- Operating system and version affected: Mac v 14.5

Additional Information

the screenshot of the simulator is an information widget that is the return message from api call, there is no error in FlutterFlow on the return side outside of success code is not 200. I believe FlutterFlow is doing something to the JWT Token on api call.

frito-pibble commented 1 month ago

I also verified this by creating simple flutter app to login and call a function. and it's working. to recap, postman and new natives flutter code via vs code works. it's only when the functions are called via the flutterflow code that this issue appears. please let me know if I can provide any additional information. I am stopped dead in the track as my app replies heavily on cloud functions.

Alezanello commented 1 month ago

Hello!

I've tried everything and could not replicate the issue. The JWT token is sending fine from my side to the Cloud Function and validating correctly.

To help resolve this, you might try sending the JWT token as a header to the Cloud Function, like this: Authorization: [jwtToken]. Then, in the Cloud Function, you can receive it with const token = req.headers['authorization'];.

This approach might help you correctly parse the JWT token outside of the body.

frito-pibble commented 1 month ago

I am still having issues. maybe it's because I am using middleware firebaseApp.use(cors({ origin: true })); stripeAPIApp.use(cors({ origin: true })); stripeWebhookApp.use(cors({ origin: true })); userApp.use(cors({ origin: true }));

firebaseApp.use(bodyParser.json()); stripeAPIApp.use(bodyParser.json()); stripeWebhookApp.use(bodyParser.json({ verify: function (req, res, buf) { const url = req.originalUrl; if (url.startsWith('/stripeWebhook')) { req.rawBody = buf.toString(); } } })); none the less as mentioned above, both postman and simple flutter app calling the APIs work. I can send video proof or jump on a quick a call if that would be helpful.

additionally, this was the same function code prior to Thurs. no changes were made on the function code yet ALL of the functions calls now have the same problem

Alezanello commented 1 month ago

Have you tried using console.log to print the JWT token before the middleware? This can help determine if the issue is with the token itself or if it's related to another part of the logic.

Please check the JWT token printed from the FlutterFlow API call and compare it with the one from Postman to see if there are any discrepancies.

frito-pibble commented 1 month ago

I made a mistake I don't think it the JWT token but instead the json package. it's still an issue but it seems I am the only one experiencing the problem. since it's working with regular flutter I will start over and try and use that. i have already wasted enough time on this. thanks for your help.

Alezanello commented 1 month ago

Hello!

Thank you for the update. I understand the frustration of dealing with these issues. Starting over sounds like a good plan if it's working for you. If you need any further assistance or run into any other problems, feel free to reach out.

Best of luck with your project, and thank you for your patience!