Skip to content

Commit

Permalink
[#1] Feat: 카카오 로그인 로직 구현
Browse files Browse the repository at this point in the history
카카오 SDK를 통한 로그인 로직입니다.
아직 테스트하지 않았으며, 서버 연동 로직은 미구현입니다.
  • Loading branch information
cucumber99 committed Jun 27, 2024
1 parent e82b364 commit 4811f28
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'dart:developer';
import 'package:flutter/widgets.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:kakao_flutter_sdk/kakao_flutter_sdk.dart' as k;
import '../models/user.dart';

class AuthController with ChangeNotifier {
Future<User?> loginWithKakao() async {
try {
if (await k.isKakaoTalkInstalled()) {
try {
await k.UserApi.instance.loginWithKakaoTalk();
log("카카오톡 로그인 성공");
} catch (e) {
log("카카오톡 로그인 실패 : $e");
await k.UserApi.instance.loginWithKakaoAccount();
log("카카오 계정 로그인 성공");
}
} else {
await k.UserApi.instance.loginWithKakaoAccount();
log("카카오 계정 로그인 성공");
}
k.User kakaoUser = await k.UserApi.instance.me();
return User(
name: kakaoUser.kakaoAccount!.name!,
email: kakaoUser.kakaoAccount!.email!,
);
} catch (e) {
log("로그인 실패 : $e");
return null;
}
}

Future<void> login() async {
User? user = await loginWithKakao();
if (user != null) {
//서버 로그인 로직 필요
notifyListeners();
} else {
return;
}
}
}

final authProvider = ChangeNotifierProvider((ref) => AuthController());

0 comments on commit 4811f28

Please sign in to comment.