mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: support customizing the supabase auth path (#3130)
This commit is contained in:
parent
f724185f1c
commit
c6401da0b5
@ -1,9 +1,14 @@
|
|||||||
import 'package:appflowy/env/env.dart';
|
import 'package:appflowy/env/env.dart';
|
||||||
|
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
import '../startup.dart';
|
import '../startup.dart';
|
||||||
|
|
||||||
bool isSupabaseInitialized = false;
|
bool isSupabaseInitialized = false;
|
||||||
|
const hiveBoxName = 'appflowy_supabase_authentication';
|
||||||
|
|
||||||
class InitSupabaseTask extends LaunchTask {
|
class InitSupabaseTask extends LaunchTask {
|
||||||
@override
|
@override
|
||||||
@ -18,10 +23,60 @@ class InitSupabaseTask extends LaunchTask {
|
|||||||
await Supabase.initialize(
|
await Supabase.initialize(
|
||||||
url: Env.supabaseUrl,
|
url: Env.supabaseUrl,
|
||||||
anonKey: Env.supabaseAnonKey,
|
anonKey: Env.supabaseAnonKey,
|
||||||
debug: true,
|
debug: kDebugMode,
|
||||||
// authFlowType: AuthFlowType.pkce,
|
localStorage: const SupabaseLocalStorage(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// customize the supabase auth storage
|
||||||
|
///
|
||||||
|
/// We don't use the default one because it always save the session in the document directory.
|
||||||
|
/// When we switch to the different folder, the session still exists.
|
||||||
|
class SupabaseLocalStorage extends LocalStorage {
|
||||||
|
const SupabaseLocalStorage()
|
||||||
|
: super(
|
||||||
|
initialize: _initialize,
|
||||||
|
hasAccessToken: _hasAccessToken,
|
||||||
|
accessToken: _accessToken,
|
||||||
|
removePersistedSession: _removePersistedSession,
|
||||||
|
persistSession: _persistSession,
|
||||||
|
);
|
||||||
|
|
||||||
|
static Future<void> _initialize() async {
|
||||||
|
HiveCipher? encryptionCipher;
|
||||||
|
|
||||||
|
// customize the path for Hive
|
||||||
|
final path = await getIt<ApplicationDataStorage>().getPath();
|
||||||
|
Hive.init(p.join(path, 'supabase_auth'));
|
||||||
|
await Hive.openBox(
|
||||||
|
hiveBoxName,
|
||||||
|
encryptionCipher: encryptionCipher,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool> _hasAccessToken() {
|
||||||
|
return Future.value(
|
||||||
|
Hive.box(hiveBoxName).containsKey(
|
||||||
|
supabasePersistSessionKey,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String?> _accessToken() {
|
||||||
|
return Future.value(
|
||||||
|
Hive.box(hiveBoxName).get(supabasePersistSessionKey) as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _removePersistedSession() {
|
||||||
|
return Hive.box(hiveBoxName).delete(supabasePersistSessionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _persistSession(String persistSessionString) {
|
||||||
|
return Hive.box(hiveBoxName).put(
|
||||||
|
supabasePersistSessionKey,
|
||||||
|
persistSessionString,
|
||||||
);
|
);
|
||||||
|
|
||||||
isSupabaseInitialized = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -628,7 +628,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.0"
|
version: "0.7.0"
|
||||||
hive:
|
hive:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: hive
|
name: hive
|
||||||
sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941"
|
sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941"
|
||||||
@ -636,7 +636,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.3"
|
version: "2.2.3"
|
||||||
hive_flutter:
|
hive_flutter:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: hive_flutter
|
name: hive_flutter
|
||||||
sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc
|
sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc
|
||||||
|
@ -98,6 +98,8 @@ dependencies:
|
|||||||
supabase_flutter: ^1.10.4
|
supabase_flutter: ^1.10.4
|
||||||
envied: ^0.3.0+3
|
envied: ^0.3.0+3
|
||||||
dotted_border: ^2.0.0+3
|
dotted_border: ^2.0.0+3
|
||||||
|
hive: ^2.2.3
|
||||||
|
hive_flutter: ^1.1.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^2.0.1
|
flutter_lints: ^2.0.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user