@@ -78,6 +78,21 @@ class SharedPreferencesLocalStorage extends LocalStorage {
78
78
if (! _useWebLocalStorage) {
79
79
WidgetsFlutterBinding .ensureInitialized ();
80
80
_prefs = SharedPreferencesAsync ();
81
+
82
+ await _maybeMigrateAccessToken ();
83
+ }
84
+ }
85
+
86
+ Future <void > _maybeMigrateAccessToken () async {
87
+ final legacyPrefs = await SharedPreferences .getInstance ();
88
+
89
+ if (legacyPrefs.containsKey (persistSessionKey)) {
90
+ final accessToken = legacyPrefs.getString (persistSessionKey);
91
+
92
+ if (accessToken != null ) {
93
+ await legacyPrefs.remove (persistSessionKey);
94
+ await _prefs.setString (persistSessionKey, accessToken);
95
+ }
81
96
}
82
97
}
83
98
@@ -118,34 +133,34 @@ class SharedPreferencesLocalStorage extends LocalStorage {
118
133
/// local storage to store pkce flow code verifier.
119
134
class SharedPreferencesGotrueAsyncStorage extends GotrueAsyncStorage {
120
135
SharedPreferencesGotrueAsyncStorage () {
121
- _initialize ();
136
+ initialize ();
122
137
}
123
138
124
- final Completer <void > _initializationCompleter = Completer ();
139
+ final Completer <void > initializationCompleter = Completer ();
125
140
126
- late final SharedPreferences _prefs ;
141
+ late final SharedPreferences prefs ;
127
142
128
- Future <void > _initialize () async {
143
+ Future <void > initialize () async {
129
144
WidgetsFlutterBinding .ensureInitialized ();
130
- _prefs = await SharedPreferences .getInstance ();
131
- _initializationCompleter .complete ();
145
+ prefs = await SharedPreferences .getInstance ();
146
+ initializationCompleter .complete ();
132
147
}
133
148
134
149
@override
135
150
Future <String ?> getItem ({required String key}) async {
136
- await _initializationCompleter .future;
137
- return _prefs .getString (key);
151
+ await initializationCompleter .future;
152
+ return prefs .getString (key);
138
153
}
139
154
140
155
@override
141
156
Future <void > removeItem ({required String key}) async {
142
- await _initializationCompleter .future;
143
- await _prefs .remove (key);
157
+ await initializationCompleter .future;
158
+ await prefs .remove (key);
144
159
}
145
160
146
161
@override
147
162
Future <void > setItem ({required String key, required String value}) async {
148
- await _initializationCompleter .future;
149
- await _prefs .setString (key, value);
163
+ await initializationCompleter .future;
164
+ await prefs .setString (key, value);
150
165
}
151
166
}
0 commit comments