Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'package:retrofit/retrofit.dart';

abstract class BaseAuthApi {
Future login(@Query('token') String token);
Future info();
}
4 changes: 4 additions & 0 deletions lib/app/modules/user/data/data_sources/remote/auth_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ abstract class AuthApi extends BaseAuthApi {
@factoryMethod
factory AuthApi(GroupsDio dio) = _AuthApi;

@override
@GET('login')
Future<void> login(@Query('token') String token);

@override
@GET('info')
Future<GroupUserModel> info();
Expand Down
4 changes: 4 additions & 0 deletions lib/app/modules/user/data/data_sources/remote/user_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ abstract class UserApi extends BaseAuthApi {
@factoryMethod
factory UserApi(ZiggleDio dio) = _UserApi;

@override
@GET('login')
Future<void> login(@Query('token') String token);

@override
@GET('info')
Future<UserModel> info();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract class RestAuthRepository implements AuthRepository {
if (token.refreshToken != null) {
await _tokenRepository.saveRefreshToken(token.refreshToken!);
}
await _api.login(token.accessToken);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

새로운 API 호출에 대한 에러 핸들링을 추가해주세요.

토큰 저장 후 추가된 _api.login(token.accessToken) 호출이 실패할 경우를 대비한 에러 핸들링이 필요합니다. 이 호출이 실패하더라도 사용자가 로그인 상태를 유지할 수 있도록 처리하거나, 실패 시 적절한 롤백 로직을 구현해야 합니다.

다음과 같이 에러 핸들링을 추가하는 것을 권장합니다:

  await _tokenRepository.saveToken(token.accessToken);
  if (token.refreshToken != null) {
    await _tokenRepository.saveRefreshToken(token.refreshToken!);
  }
- await _api.login(token.accessToken);
+ try {
+   await _api.login(token.accessToken);
+ } catch (e) {
+   // API 호출 실패 시 로깅하지만 로그인은 계속 진행
+   // 또는 필요에 따라 토큰을 롤백할 수 있음
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await _api.login(token.accessToken);
await _tokenRepository.saveToken(token.accessToken);
if (token.refreshToken != null) {
await _tokenRepository.saveRefreshToken(token.refreshToken!);
}
- await _api.login(token.accessToken);
+ try {
+ await _api.login(token.accessToken);
+ } catch (e) {
+ // API 호출 실패 시 로깅하지만 로그인은 계속 진행
+ // 또는 필요에 따라 토큰을 롤백할 수 있음
+ }
🤖 Prompt for AI Agents
In lib/app/modules/user/data/repositories/rest_auth_repository.dart around line
31, the new await _api.login(token.accessToken) call lacks error handling; wrap
this call in a try/catch so the repository handles failures: either swallow the
error (log it) and return success so the saved token keeps the user logged in,
or perform a rollback by deleting the stored token and rethrowing or returning a
failure result; ensure you log the error and choose a clear contract
(bool/result) so callers know whether login finalization succeeded.

}

@override
Expand Down