Skip to content
Client
Server

Reference / @open-music-sdk/user-token / acceptUserToken

Function: acceptUserToken() ​

ts
function acceptUserToken(
   client, 
   store, 
   userId, 
   token, 
   options?
): Promise<string>;

Defined in: user-token/src/accept.ts:31

Takes a token in for one of your users: asks Apple whether it works and only then stores it under userId, replacing the token already there. Resolves to the listener's storefront. Whatever stops it (Apple's verdict, a failure to ask, an abort) leaves the store as it was.

It rejects as validateUserToken does, and with whatever the store throws. This is all userTokenIntake does once it has read its request; call it yourself from a framework that hands you something other than a web-standard Request.

Parameters ​

client ​

tAppleMusicClient

The client to ask Apple with.

store ​

tUserTokenStore

Where the token goes once Apple has accepted it: the store your client's forUser() reads.

userId ​

string

Your own id for the user, which the token is stored under.

token ​

string

The Music User Token to take in.

options? ​

tValidateOptions = {}

A signal to abort with.

Returns ​

Promise<string>

The listener's storefront id, such as us.

Throws ​

TypeError if client is not a client, store lacks get, set or delete, userId is not a string with something in it, token is not a token, options is not a plain object, or options.signal is no AbortSignal, before Apple is asked.

Throws ​

AppleMusicError as validateUserToken throws it: UserTokenInvalid when Apple will not take the token, otherwise what asking failed with.

Throws ​

Whatever a token provider, hook or rate limiter throws, as client.request passes it on.

Throws ​

Whatever store.set rejects with, once Apple has accepted the token.

Throws ​

The reason options.signal aborted with, when it does.

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.