pinafore/src/routes/_actions/doQuickLoginIfNecessary.js
Nolan Lawson 16e66346d7
fix!: remove esm package, use native Node ES modules (#2064)
BREAKING CHANGE: Node v12.20+, v14.14+, or v16.0+ is required

* fix!: remove esm package, use native Node ES modules

* fix: fix some CJS imports
2021-07-04 20:19:04 -07:00

36 lines
1,000 B
JavaScript

// "Secret" API to quickly log in with an access token and instance name.
// Used in the integration tests. Can't see a problem with exposing this publicly
// since you would have to know the access token anyway.
import { store } from '../_store/store.js'
import { goto } from '../../../__sapper__/client.js'
export function doQuickLoginIfNecessary () {
const params = new URLSearchParams(location.search)
const accessToken = params.get('accessToken')
const instanceName = params.get('instanceName')
if (!accessToken || !instanceName) {
return
}
const {
loggedInInstances,
loggedInInstancesInOrder
} = store.get()
loggedInInstances[instanceName] = {
access_token: accessToken
}
if (!loggedInInstancesInOrder.includes(instanceName)) {
loggedInInstancesInOrder.push(instanceName)
}
store.set({
currentInstance: instanceName,
loggedInInstances,
loggedInInstancesInOrder
})
store.save()
goto('/') // re-navigate without the URL params
}