Cleaner error message on aborted Passkey operations.
This commit is contained in:
@@ -4,13 +4,18 @@ import aWebSocket from '@/utils/awaitable-websocket'
|
||||
export async function register(url, options) {
|
||||
if (options) url += `?${new URLSearchParams(options).toString()}`
|
||||
const ws = await aWebSocket(url)
|
||||
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const registrationResponse = await startRegistration({ optionsJSON })
|
||||
ws.send_json(registrationResponse)
|
||||
const result = await ws.receive_json()
|
||||
ws.close()
|
||||
return result;
|
||||
try {
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const registrationResponse = await startRegistration({ optionsJSON })
|
||||
ws.send_json(registrationResponse)
|
||||
const result = await ws.receive_json()
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error)
|
||||
// Replace useless and ugly error message from startRegistration
|
||||
throw Error(error.name === "NotAllowedError" ? 'Passkey registration cancelled' : error.message)
|
||||
} finally {
|
||||
ws.close()
|
||||
}
|
||||
}
|
||||
|
||||
export async function registerUser(user_name) {
|
||||
@@ -26,11 +31,16 @@ export async function registerWithToken(token) {
|
||||
|
||||
export async function authenticateUser() {
|
||||
const ws = await aWebSocket('/auth/ws/authenticate')
|
||||
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const authResponse = await startAuthentication({ optionsJSON })
|
||||
ws.send_json(authResponse)
|
||||
const result = await ws.receive_json()
|
||||
ws.close()
|
||||
return result
|
||||
try {
|
||||
const optionsJSON = await ws.receive_json()
|
||||
const authResponse = await startAuthentication({ optionsJSON })
|
||||
ws.send_json(authResponse)
|
||||
const result = await ws.receive_json()
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Authentication error:', error)
|
||||
throw Error(error.name === "NotAllowedError" ? 'Passkey authentication cancelled' : error.message)
|
||||
} finally {
|
||||
ws.close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user