fix: improve Turnstile configuration - handle web/mobile differences, add error callbacks
This commit is contained in:
parent
5674c8e4f8
commit
3d4b661370
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';
|
import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../config/api_config.dart';
|
import '../../config/api_config.dart';
|
||||||
|
|
@ -16,10 +17,24 @@ class TurnstileWidget extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// On web, use the full API URL
|
||||||
|
// On mobile, Turnstile handles its own endpoints
|
||||||
|
final effectiveBaseUrl = kIsWeb ? (baseUrl ?? ApiConfig.baseUrl) : null;
|
||||||
|
|
||||||
return CloudflareTurnstile(
|
return CloudflareTurnstile(
|
||||||
siteKey: siteKey,
|
siteKey: siteKey,
|
||||||
baseUrl: baseUrl ?? ApiConfig.baseUrl,
|
baseUrl: effectiveBaseUrl,
|
||||||
onTokenReceived: onToken,
|
onTokenReceived: onToken,
|
||||||
|
onError: (error) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Turnstile error: $error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onExpired: () {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Turnstile token expired');
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue