@@ -73,6 +73,10 @@ public class BugReportUI : MonoBehaviour
7373 [ FormerlySerializedAs ( "authToken" ) ]
7474 public string AuthToken ;
7575
76+ // Device authentication manager for user login flow
77+ [ Tooltip ( "Device Authentication (Optional). If set, the user may be authenticated via device auth." ) ]
78+ [ SerializeField ] private DeviceAuthManager deviceAuthManager ;
79+
7680 // If set, this email address will be used as the default email address of the reporter.
7781 // This is a hidden field since it's purpose is to be pre-filled programmatically by the developer if the user is somehow already logged in with a specific email address.
7882 [ HideInInspector , FormerlySerializedAs ( "defaultEmailAddress" ) ]
@@ -174,13 +178,14 @@ void Start()
174178 Debug . LogError ( "Project ID is not set. I won't be able to submit bug reports." ) ;
175179 }
176180
181+ // Check for auth token if not using device auth
177182 if ( string . IsNullOrEmpty ( AuthToken ) )
178183 {
179- Debug . LogError ( "Auth token is not set. I won't be able to submit bug reports ." ) ;
184+ Debug . LogWarning ( "Auth token is not set. Bug reports will only work if device authentication is available and user is signed in ." ) ;
180185 }
181186
182- // auth token must start with tkn-
183- if ( ! AuthToken . StartsWith ( "tkn-" ) )
187+ // auth token must start with tkn- if provided
188+ if ( ! string . IsNullOrEmpty ( AuthToken ) && ! AuthToken . StartsWith ( "tkn-" ) )
184189 {
185190 Debug . LogError ( "Auth token must start with tkn-. I won't be able to submit bug reports." ) ;
186191 }
@@ -371,8 +376,9 @@ void SubmitBugReport()
371376 gameRecorder = _gameRecorder ;
372377 }
373378
374- // Create Issue instance and post it
375- Issue issue = new Issue ( SubmitEndpoint , ProjectID , AuthToken , MessagePanelUI , ReportSubmittedUI , gameRecorder ) ;
379+ // Create Issue instance and post it with authentication
380+ string effectiveAuthToken = GetEffectiveAuthToken ( ) ;
381+ Issue issue = new Issue ( SubmitEndpoint , ProjectID , effectiveAuthToken , MessagePanelUI , ReportSubmittedUI , gameRecorder ) ;
376382 _issues . Add ( issue ) ;
377383
378384
@@ -415,8 +421,18 @@ void SubmitBugReport()
415421 _screenshots . Clear ( ) ;
416422 _logFiles . Clear ( ) ;
417423
418- // show the report submitted UI
419- ReportSubmittedUI . Show ( issue , DefaultEmailAddress ) ;
424+ // Check if user is authenticated via device auth
425+ if ( IsUserAuthenticatedViaDeviceAuth ( ) )
426+ {
427+ // For authenticated users: publish immediately and show thanks
428+ StartCoroutine ( PublishIssueAndShowThanks ( issue ) ) ;
429+ }
430+ else
431+ {
432+ // For non-authenticated users: show email UI which handles publishing
433+ string effectiveEmail = GetEffectiveEmailAddress ( ) ;
434+ ReportSubmittedUI . Show ( issue , effectiveEmail ) ;
435+ }
420436
421437 // hide bug report panel
422438 BugReportPanel . SetActive ( false ) ;
@@ -447,5 +463,71 @@ class ErrorMessage {
447463 class IssueResponse {
448464 public string id ;
449465 }
466+
467+ #region Device Authentication Integration
468+
469+ private bool IsDeviceAuthAvailable ( )
470+ {
471+ return deviceAuthManager != null && ! string . IsNullOrEmpty ( ProjectID ) ;
472+ }
473+
474+ private string GetEffectiveAuthToken ( )
475+ {
476+ // Check if user is authenticated via device auth at submit time
477+ if ( deviceAuthManager != null && deviceAuthManager . IsAuthenticated ( ) )
478+ {
479+ string jwtToken = deviceAuthManager . JwtToken ;
480+ if ( ! string . IsNullOrEmpty ( jwtToken ) )
481+ {
482+ // Return AuthToken,JwtToken format when signed in
483+ return string . IsNullOrEmpty ( AuthToken ) ? jwtToken : $ "{ AuthToken } ,{ jwtToken } ";
484+ }
485+ }
486+
487+ // Fall back to configured auth token only
488+ return AuthToken ;
489+ }
490+
491+ private string GetEffectiveEmailAddress ( )
492+ {
493+ // If user is authenticated via device auth, don't use email address
494+ // Backend already knows who the reporter is from the JWT token
495+ if ( deviceAuthManager != null && deviceAuthManager . IsAuthenticated ( ) )
496+ {
497+ // Return null/empty - backend knows the user from JWT token
498+ return null ;
499+ }
500+
501+ // Fall back to configured default email for non-authenticated users
502+ return DefaultEmailAddress ;
503+ }
504+
505+ public void SetDeviceAuthManager ( DeviceAuthManager authManager )
506+ {
507+ deviceAuthManager = authManager ;
508+ }
509+
510+ private bool IsUserAuthenticatedViaDeviceAuth ( )
511+ {
512+ return deviceAuthManager != null && deviceAuthManager . IsAuthenticated ( ) ;
513+ }
514+
515+ private IEnumerator PublishIssueAndShowThanks ( Issue issue )
516+ {
517+ // Publish the issue immediately (no email needed - backend knows user from JWT)
518+ var publishCoroutine = issue . Publish ( false ) ; // false = don't email the report
519+ yield return publishCoroutine ;
520+
521+ // Check if publishing was successful by checking if the coroutine completed without errors
522+ // Note: Issue.Publish() should handle its own errors internally, so we assume success here
523+ MessagePanelUI . ShowMessagePanel ( "Thank You" , "Your bug report has been submitted successfully. Thank you for helping us improve the game!" ) ;
524+ }
525+
526+ void OnDestroy ( )
527+ {
528+ // Cleanup handled automatically since we don't subscribe to events
529+ }
530+
531+ #endregion
450532 }
451533}
0 commit comments