@@ -3,7 +3,9 @@ import 'dart:convert';
33import 'dart:io' ;
44
55import 'package:firebase_auth/firebase_auth.dart' ;
6+ import 'package:flutter/foundation.dart' ;
67import 'package:http/http.dart' ;
8+ import 'package:jwt_decoder/jwt_decoder.dart' ;
79
810import '../../codelessly_sdk.dart' ;
911
@@ -96,7 +98,6 @@ class CodelesslyAuthManager extends AuthManager {
9698 // the server attached a custom claim to the user's token to allow
9799 // Codelessly Cloud Data to work.
98100 _idTokenResult = await firebaseAuth.currentUser! .getIdTokenResult (true );
99- final claims = _idTokenResult! .claims;
100101
101102 if (cacheManager.isCached (authCacheKey)) {
102103 try {
@@ -114,11 +115,7 @@ class CodelesslyAuthManager extends AuthManager {
114115 // also need to invalidate the cache and fetch auth data from the
115116 // server and revalidate.
116117 if (cachedAuthData.authToken == config.authToken &&
117- claims != null &&
118- claims.containsKey ('project_ids' ) &&
119- claims['project_ids' ] is List &&
120- (claims['project_ids' ] as List )
121- .contains (cachedAuthData.projectId)) {
118+ checkClaimsForProject (_idTokenResult, cachedAuthData.projectId)) {
122119 _authData = cachedAuthData;
123120 _authStreamController.add (_authData);
124121 } else {
@@ -201,10 +198,18 @@ class CodelesslyAuthManager extends AuthManager {
201198 return false ;
202199 }
203200
204- final claims = result.claims;
201+ final Map <String , dynamic > claims;
202+
203+ // https://github.com/firebase/flutterfire/issues/11768#issuecomment-1888363494
204+ // A temporary fix for windows platform until the issue is resolved.
205+ if (! kIsWeb && defaultTargetPlatform == TargetPlatform .windows) {
206+ claims = JwtDecoder .decode (result.toString ());
207+ } else {
208+ claims = result.claims ?? {};
209+ }
205210
206211 log ('User claims: $claims ' , largePrint: true );
207- if (claims == null ) {
212+ if (claims.isEmpty ) {
208213 log ('User claims is null. Cannot check claims for project id [$projectId ]' );
209214 return false ;
210215 }
@@ -297,7 +302,7 @@ class CodelesslyAuthManager extends AuthManager {
297302 try {
298303 log ('Authenticating token...' );
299304
300- final authData = await verifyProjectAuthToken (
305+ final AuthData ? authData = await verifyProjectAuthToken (
301306 userToken: _idTokenResult! .token! ,
302307 config: config,
303308 postSuccess: postAuthSuccess,
@@ -384,8 +389,10 @@ class CodelesslyAuthManager extends AuthManager {
384389 // successful.
385390 if (result.statusCode == 200 ) {
386391 logger.log (
387- label, 'Successful auth token verification response received.' ,
388- largePrint: true );
392+ label,
393+ 'Successful auth token verification response received.' ,
394+ largePrint: true ,
395+ );
389396
390397 // Parse the body of the response to JSON.
391398 final jsonBody = jsonDecode (result.body);
0 commit comments