accessToken and the js api

I’m updating some old code that used the deprecated SparkJS lib. I can’t seem to login it using the accessToken anymore.

Old code that worked:

spark.login({accessToken: token}, () => {
		console.log("login works")
	})

The new api only seems to only accept credentials with username and password. Is is not possible to use an accessToken anymore?

You only need to login to get the access_token. You can save the access token and reuse it later directly as the auth parameter to any call without logging in again.

Here’s my example of using the new Javascript API:

2 Likes

Thanks for helping.

I understand how the token works now but I liked using the accessToken to login on my node.js server. I shared the code with a friend and it was convenient to not share the actual log in credentials.

How is that any different now?
Using the credentials in the current SDK does nothing more than getting an access token and saving that to a variable. If you’ve already got the access token, simply skip the login step and use it directly. “Logging in” dumbed down is nothing more than retrieving an access token for your credentials, which you’ve already got :wink:

1 Like

Oh so I don’t need to login anymore, that makes total sense, thanks! I was still in the mindset that you login once and then just made requests without the need of an auth token.

Sorry for being confused :slight_smile: