Managing Tokens
Exchange an authorization code
issueAccessTokenWithCode() exchanges an existing authorization code for a KakaoLoginToken on iOS and web. Use it when handling a code obtained through a separate authorization flow. On iOS, login() performs the exchange. On web, login() redirects to authorization; exchange the code returned by that redirect separately.
import { issueAccessTokenWithCode } from '@react-native-kakao/user';
const token = await issueAccessTokenWithCode({
code: authorizationCode,
codeVerifier,
redirectUri,
});
codeVerifier is the verification value created for a PKCE (Proof Key for Code Exchange) authorization request. Pass the same value if that request used PKCE. redirectUri must also match the authorization request. On iOS, omitting it uses the initialized SDK's default redirect URI. Web requires it.
The iOS SDK stores the issued tokens. Web uses the REST API key supplied during Core initialization, then stores the access token in the JavaScript SDK and the library's web storage. The refresh token is returned but not stored. Pass web: { clientSecret } if your web app requires a client secret. Expiry timestamps use Unix seconds, lifetimes use seconds, and scopes contains scope IDs.
The public Android SDK does not provide a separate code-exchange API, so Android rejects with Package-UnsupportedPlatform. Use login() or loginWithKakao() there. The existing issueAccessTokenWithCodeWeb() remains web only and returns its existing REST response shape without storing tokens.
Check Stored Token Presence
hasToken() returns Promise<boolean> on Android, iOS, and web. It reads the current platform SDK's local token storage without calling Kakao's token information API or refreshing a token. This lets an app check for stored credentials during startup or while offline.
import { hasToken, isLogined } from '@react-native-kakao/user';
const hasStoredToken = await hasToken();
if (hasStoredToken) {
const isTokenValid = await isLogined();
}
true means the SDK has a stored token. That token may have expired or been revoked. Use isLogined() to validate it with Kakao before treating the user as authenticated.
The method returns only a boolean and does not expose the stored token.
Query token information
getAccessToken() validates the access token with Kakao and returns the user ID, app ID, and remaining lifetime in seconds. It does not return the access token string.
It is defined as follows.
export function getAccessToken(): Promise<KakaoAccessTokenInfo>;
The type is as follows.
export interface KakaoAccessTokenInfo {
id?: number;
appId: number;
expiresIn: number;
}
Example
getAccessToken();
Refresh tokens
refreshToken() refreshes the token stored by the Android or iOS SDK. Pass refreshToken({ token }) to choose an existing token explicitly. The SDK uses that token's refresh token even when its storage is empty or contains a different token.
import { refreshToken } from '@react-native-kakao/user';
const refreshedStoredToken = await refreshToken();
const refreshedExternalToken = await refreshToken({ token: previousToken });
const refreshedWithoutRequestLogs = await refreshToken({
ios: { loggingEnabled: false },
});
Pass the KakaoLoginToken returned by login() or issueAccessTokenWithCode() as previousToken. A refresh-token string alone is insufficient because the SDK retains the previous expiry information when it does not issue a new refresh token. An expired access token can still be refreshed if its refresh token remains valid.
On success, the SDK stores the updated token and returns the same KakaoLoginToken shape. Expiry timestamps use Unix seconds; remaining lifetimes are calculated from each expiry timestamp in seconds.
ios.loggingEnabled defaults to true, preserving the iOS SDK's default logging behavior. Set it to false to hide this refresh request's logs and response body without changing global SDK logging. iOS SDK 2.29.0 still logs a response: - placeholder. It applies to stored and explicitly supplied tokens. Android ignores this iOS option.
If the selected refresh token is missing or expired, the method rejects with the Kakao SDK error. Call login() again. The JavaScript SDK does not expose token refresh, so web rejects with Package-UnsupportedPlatform whether or not a token is supplied.
For web token exchange and storage, follow Web login.