MapComplete/app/land.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-12-31 16:31:01 +01:00
import { OsmConnection } from "../src/Logic/Osm/OsmConnection"
import Constants from "../src/Models/Constants"
2024-12-31 19:55:08 +01:00
import { Utils } from "../src/Utils"
import { UIEventSource } from "../src/Logic/UIEventSource"
import { QueryParameters } from "../src/Logic/Web/QueryParameters"
2024-12-31 16:31:01 +01:00
console.log("Authorizing...")
const key = Constants.osmAuthConfig.url + "oauth2_state"
const st = window.localStorage.getItem(key)
console.log("Prev state is", key, st)
2024-12-31 19:55:08 +01:00
const tokenSrc = new UIEventSource("")
const debug = new UIEventSource<string[]>([])
const connection = new OsmConnection()
connection.finishLogin(async () => {
let token: string = undefined
let attempt = 0
do {
await Utils.waitFor(500)
token = connection.getToken()
2025-02-10 02:04:58 +01:00
tokenSrc.set("Trying to get token (" + attempt + ")")
attempt++
const dbg = []
2025-02-10 02:04:58 +01:00
Object.keys(localStorage).forEach((key) => {
dbg.push(`${key} - ${localStorage.getItem(key)}`)
})
debug.set(dbg)
2025-02-10 02:04:58 +01:00
if (attempt > 10) {
QueryParameters.ClearAll()
window.location.reload()
}
} while (!token)
console.log("Login finished, redirecting to passthrough; token is " + token)
tokenSrc.set(token)
if (!token) {
tokenSrc.set("ERROR: no token retrieved!")
return
}
2025-07-07 00:06:49 +02:00
window.location.href = "https://app.mapcomplete.org/passthrough.html?oauth_token=" + token
2024-12-31 16:31:01 +01:00
})