-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
카카오 SDK를 통한 로그인 로직입니다. 아직 테스트하지 않았으며, 서버 연동 로직은 미구현입니다.
- Loading branch information
1 parent
e82b364
commit 4811f28
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |