Skip to content

Commit 2d627ea

Browse files
Merge pull request #62 from owlistic-notes/user-profile-fixes
Clear preferences on logout
2 parents 6adc143 + 3274072 commit 2d627ea

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/backend/services/auth_service.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ func (s *AuthService) Login(db *database.Database, email, password string) (stri
4242
return "", ErrInvalidCredentials
4343
}
4444

45-
// Check if the user has any notebooks
46-
var notebookCount int64
47-
if err := db.DB.Model(&models.Notebook{}).Where("user_id = ?", user.ID).Count(&notebookCount).Error; err != nil {
48-
return "", err
49-
}
50-
5145
// Use the utility function instead
5246
tokenString, err := token.GenerateToken(user.ID, user.Email, s.jwtSecret, s.jwtExpiration)
5347
if err != nil {

src/frontend/lib/services/auth_service.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,15 @@ class AuthService extends BaseService {
230230

231231
Future<bool> logout() async {
232232
try {
233-
// Call logout endpoint if it exists and we have a token
234-
if (isLoggedIn) {
235-
try {
236-
await authenticatedPost('/api/v1/logout', {});
237-
} catch (e) {
238-
// Just log the error but continue with local logout
239-
_logger.error('Error calling logout endpoint', e);
240-
}
241-
}
242-
243233
// Clear token regardless of response
244234
await clearToken();
235+
await clearPreferences();
245236
_logger.info('Logged out successfully');
246237
return true;
247238
} catch (e) {
248239
_logger.error('Error during logout', e);
249240
await clearToken(); // Still clear token on error
241+
await clearPreferences();
250242
return false;
251243
}
252244
}
@@ -424,6 +416,17 @@ Future<String?> getCurrentUserId() async {
424416
return null;
425417
}
426418
}
419+
420+
Future<void> clearPreferences() async {
421+
try {
422+
// First try to get from shared preferences for better performance
423+
final prefs = await SharedPreferences.getInstance();
424+
prefs.clear();
425+
} catch (e) {
426+
_logger.error('Error getting current user ID', e);
427+
return null;
428+
}
429+
}
427430

428431
// Safe login with better error handling
429432
Future<bool> loginSafe(String email, String password) async {

0 commit comments

Comments
 (0)