---
url: https://developers.webzenk.kr/sdk/html5/features.md
---
# 로그인·저장·랭킹·이벤트

## 로그인

```js
await api.auth.login()                       // 자동
await api.auth.login({ interactive: true })  // 삼성 계정이 없으면 삼성 로그인 창 (버튼에서)
await api.auth.loginGoogle(credential)       // Google Identity Services 의 ID 토큰
await api.auth.loginApple(idToken, nonce)    // Sign in with Apple JS
await api.auth.linkPlatform()                // 지금 게스트 계정에 삼성 계정 연결
await api.auth.linkGoogle(credential)

api.auth.playerId                            // 서버 유저 ID
api.auth.onSessionLost = (e) => showLogin()  // 제재·탈퇴·토큰 폐기
await api.auth.logout()
await api.auth.deleteAccount()               // 탈퇴 요청
```

* 토큰 만료는 SDK가 갱신합니다. 세션은 브라우저 저장소에 보관돼 새로고침해도 같은 유저입니다.
* 게스트는 브라우저 단위입니다. 브라우저 데이터를 지우면 새 게스트가 됩니다.

## 저장

```js
const save = await api.storage.get('save')          // 없으면 null — save.value, save.version
await api.storage.set('save', { stage: 3, gold: 120 })
await api.storage.update('save', (cur) => ({ ...cur, gold: (cur?.gold ?? 0) + 10 }))   // 충돌 시 재시도
await api.storage.setMany([{ key: 'a', value: 1 }, { key: 'b', value: 2 }])
await api.storage.delete('a')
await api.storage.set('profile', { nick: 'wk' }, { isPublic: true })
const others = await api.storage.publicOf(playerId)
```

## 랭킹

```js
const r = await api.leaderboard.submit('weekly', 1530)   // { score, rank, total, updated }
const top = await api.leaderboard.top('weekly', 50)
const around = await api.leaderboard.me('weekly', 5)
const last = await api.leaderboard.season('weekly', 202646)
```

## 이벤트

```js
api.events.track('stage_clear', { stage: 3, time_sec: 72 })
```

5초마다 또는 20건이 쌓이면 보내고, 페이지가 숨겨질 때도 보냅니다. 실패하면 브라우저에 보관했다가 다시 보냅니다.

## 서버 시각

```js
api.serverTime()   // epoch 초
```
