Skip to main content

getUserKeyForGame

Deprecated

getUserKeyForGame is deprecated. Use getAnonymousKey instead — the type and behavior are identical.

Issues an anonymous key for game mini-apps, allowing your server to identify a game session without direct access to the user's Toss account.

Signature

import { getUserKeyForGame } from '@apps-in-toss/web-framework';

declare function getUserKeyForGame(): Promise<
| { key: string }
| 'INVALID_CATEGORY'
| 'ERROR'
| undefined
>;

Parameters

None.

Returns

  • Promise<{ key: string } | 'INVALID_CATEGORY' | 'ERROR' | undefined>
    • { key: string } — Key issued successfully. Use it as a short-lived session token.
    • 'INVALID_CATEGORY' — Called from a mini-app that is not in the game category.
    • 'ERROR' — Unknown error.
    • undefined — App version is below the minimum supported version.

Permission

No permission required. Account binding is handled by the Toss session.

Migration

Replace getUserKeyForGame with getAnonymousKey:

// Old
import { getUserKeyForGame } from '@apps-in-toss/web-framework';
const result = await getUserKeyForGame();

// Recommended
import { getAnonymousKey } from '@apps-in-toss/web-framework';
const result = await getAnonymousKey();

Examples

Minimal

import { getUserKeyForGame } from '@apps-in-toss/web-framework';

const result = await getUserKeyForGame();

if (!result) {
console.warn('App version is below the minimum supported version.');
} else if (result === 'INVALID_CATEGORY') {
console.error('Must be called from a game-category mini-app.');
} else if (result === 'ERROR') {
console.error('Failed to issue anonymous key.');
} else {
console.log('Anonymous key:', result.key);
}

Try it live

Run the getUserKeyForGame card on the Auth page in sdk-example.

Open in sdk-example

External references