Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions lib/features/auth/services/puter_bridge_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,34 +238,11 @@ class PuterBridgeService {
await initializeBridge();
}

final isAiAction =
action.startsWith('analyze_') ||
action.startsWith('generate_') ||
action == 'compare_foods';
if (isAiAction) {
final cachedToken = _storageService.getPuterToken();
if (cachedToken == null || cachedToken.trim().isEmpty) {
throw PuterAuthException(
'Please log in with your Puter account to scan food and analyze nutrition.',
);
}
final safeToken = cachedToken
.trim()
.replaceAll(r'\', r'\\')
.replaceAll("'", r"\'")
.replaceAll('"', r'\"');
await _webViewController?.runJavaScript('''
try {
if (!puter.authToken || puter.authToken !== '$safeToken') {
if (typeof puter.setAuthToken === 'function') {
puter.setAuthToken('$safeToken');
}
puter.authToken = '$safeToken';
if (puter.auth) puter.auth.token = '$safeToken';
}
} catch (_) {}
''');
}
// Puter web sign-in authenticates the SDK inside this WebView. That valid
// SDK session does not necessarily expose a raw token to Flutter storage.
// Do not require a separately stored token or overwrite the SDK session
// before AI calls. The JavaScript bridge checks puter.auth.isSignedIn()
// and lets the official SDK authorize the request in its own context.

final String requestId = const Uuid().v4();
final completer = Completer<dynamic>();
Expand Down
Loading