Skip to content

Commit 0e85c58

Browse files
authored
Merge pull request #394 from Scriptbash/refresh-auth
Refresh auth on app start
2 parents 865ad01 + 7a0ca3f commit 0e85c58

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/services/pocketbase_service.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ class PocketBaseService {
3939

4040
_client = PocketBase(savedUrl, authStore: store);
4141
_isInitialized = true;
42+
43+
await refreshAuth();
44+
}
45+
46+
Future<void> refreshAuth() async {
47+
if (client.authStore.isValid) {
48+
try {
49+
await client.collection('users').authRefresh();
50+
} catch (e) {
51+
if (e is ClientException && e.statusCode != 0) {
52+
client.authStore.clear();
53+
}
54+
}
55+
}
4256
}
4357

4458
Future<RecordAuth> register(String email, String password) async {

0 commit comments

Comments
 (0)