로그인 로직 관련 문의 입니다

문의 시 사용하시는 SDK 버전 정보와 플랫폼(Android / iOS)를 알려주세요.

요약

AuthCodeClient 를 이용하여 로그인 시 첫 로그인은 문제 없이 작동 하나, 회원 탈퇴, 카카오 계정 연동 해제(카카오톡 어플 내에서) 후 재 로그인 시 null check 오류 발생
UserApi 로 로그인 시 문제 발생 하지 않음

두 객체에 어떤 차이가 있기에 이런 차이를 보이는지 문의 드립니다.

sdk

kakao_flutter_sdk: ^0.9.0

flutter docter

[✓] Flutter (Channel stable, 2.5.1, on macOS 11.6 20G165 darwin-arm, locale ko-KR)
• Flutter version 2.5.1 at /Users/choijunho/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ffb2ecea52 (3달 전), 2021-09-17 15:26:33 -0400
• Engine revision b3af521a05
• Dart version 2.14.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/choijunho/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Users/choijunho/Downloads/Android Studio arm.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.1, Build version 13A1030d
• CocoaPods version 1.11.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
:hammer: https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
:hammer: https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] Android Studio (version 2020.3)
• Android Studio at /Users/choijunho/Downloads/Android Studio arm.app/Contents
• Flutter plugin can be installed from:
:hammer: https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
:hammer: https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.62.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.28.0

[✓] Connected device (2 available)
• 정다희의 iPhone 8 (mobile) • 13050b4506147e639956cd30fd2534d7e751ac6a • ios • iOS 14.4.2 18D70

코드정보

  Future<myUser.User?> login(bool installed) async {
try {
  ///정상 작동 코드
  final code = installed ? await UserApi.instance.loginWithKakaoTalk() : await UserApi.instance.loginWithKakaoAccount();

  ///아래 코드에서 유저 탈퇴, 계정연동 해제 후 다시 AuthCodeClient 로 접근 시 로그인 창이 뜨지 않음
  ///---Exception: null check operator used on a null value---
  // final client = AuthCodeClient.instance;
  // var code = installed ? await client.requestWithTalk() : await client.requestWithAgt(["account_email", "talk_message", "profile_nickname", "profile_image"]);

  await _issueAccessToken(token: code).then((user) {
    _user = user;
    Log.d(user);
  });
  return _user;
} on KakaoAuthException catch (e) {
  Log.d("카카오 로그인 오류 Auth $e");
  return null;
} on KakaoClientException catch (e) {
  Log.d("카카오 로그인 오류 Client $e");
  return null;
}
}

null check operator used on a null value

in auth_code.dart

Future<String> requestWithAgt(List<String> scopes,
  {String? clientId, String? redirectUri}) async {
final agt = await _kauthApi.agt(); ------------------------> ///null
final finalRedirectUri = redirectUri ?? "kakao${_platformKey()}://oauth";
final params = {
  "client_id": clientId ?? _platformKey(),
  "redirect_uri": finalRedirectUri,
  "response_type": "code",
  "agt": agt,
  "scope": scopes.length == 0 ? null : scopes.join(" "),
  "ka": await KakaoContext.kaHeader
};
params.removeWhere((k, v) => v == null);
final url = Uri.https(KakaoContext.hosts.kauth, "/oauth/authorize", params);
return _parseCode(
    await launchBrowserTab(url, redirectUri: finalRedirectUri));
}

in auth_api.dart

/// Issues temporary agt (access token-generated token), which can be used to acquire auth code.
Future<String> agt({String? clientId, String? accessToken}) async {
  final tokenInfo = await _tokenManagerProvider.manager.getToken();
  final data = {
    "client_id": clientId ?? KakaoContext.platformClientId,
    "access_token": accessToken ?? tokenInfo!.accessToken -------------------> ///null
  };

  return await ApiFactory.handleApiError(() async {
    final response = await _dio.post("/api/agt", data: data);
    return response.data["agt"];
  });
}

안녕하세요~

답변이 조금 늦었네요

결론부터 말씀드리면 AuthCodeClient.requestWithAgt() 메서드는 로그인을 위한 메서드가 아니기 때문입니다. requestWithAgt() 는 로그인 상태에서 미동의한 항목에 대한 추가 동의가 필요할 때 사용되는 메서드이므로 로그인 코드들과는 다른 용도로 사용됩니다.

로그인을 구현하기 위해서는 UserApi.loginWithKakaoTalk()UserApi.loginWithKakaoAccount() 를 사용하시기를 권장드리나, 혹시 직접 구현하고 싶으시다면

final client = AuthCodeClient.instance;
var code = installed ? await client.requestWithTalk() : await client.request();

로 구현하셔서 인가 코드를 발급 받으신 뒤, 해당 코드를 사용해 토큰을 발급받으시면 됩니다.

1개의 좋아요

정확한 답변 감사 드립니다 ^^

1개의 좋아요