Files
speckle-connectors-dui/lib/authn/useAuthManager.ts
T
Oğuzhan Koral 095ccf114d feat: auth in dui (#71)
* feat: auth in dui

* feat: enable auth with registered app

* feat: handle exceptions
2025-10-27 15:31:56 +03:00

23 lines
577 B
TypeScript

const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const CHALLENGE_KEY = 'speckle_challenge'
export function useAuthManager() {
const generateChallenge = (): string => {
let result = ''
for (let i = 0; i < 12; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length))
}
localStorage.setItem(CHALLENGE_KEY, result) // <-- persist it
return result
}
const getChallenge = (): string | null => {
return localStorage.getItem(CHALLENGE_KEY)
}
return {
getChallenge,
generateChallenge
}
}