Use Telegram Login Widget for web auth
Some checks failed
Build and deploy Flutter Web / build (push) Has been cancelled
Some checks failed
Build and deploy Flutter Web / build (push) Has been cancelled
This commit is contained in:
21
lib/auth/telegram_session_web.dart
Normal file
21
lib/auth/telegram_session_web.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
const telegramLoginStorageKey = 'mapflow.telegramLoginData';
|
||||
|
||||
@JS('window.Telegram.WebApp.initData')
|
||||
external JSString? get _telegramInitData;
|
||||
|
||||
@JS('JSON.stringify')
|
||||
external JSString _jsonStringify(JSAny? value);
|
||||
|
||||
String telegramInitData() => _telegramInitData?.toDart ?? '';
|
||||
|
||||
String telegramLoginData() =>
|
||||
web.window.localStorage.getItem(telegramLoginStorageKey) ?? '';
|
||||
|
||||
void saveTelegramLoginData(JSAny? user) {
|
||||
final encoded = _jsonStringify(user).toDart;
|
||||
web.window.localStorage.setItem(telegramLoginStorageKey, encoded);
|
||||
}
|
||||
Reference in New Issue
Block a user