feat: dynamic login and registering (#3604)

This commit is contained in:
dni ⚡
2025-12-04 11:50:45 +01:00
committed by GitHub
parent 73634e5161
commit 625fa6503c
11 changed files with 49 additions and 34 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+6
View File
@@ -89,6 +89,12 @@ window._lnbitsApi = {
}
})
},
getAuthUser() {
return axios({
method: 'GET',
url: '/api/v1/auth'
})
},
login(username, password) {
return axios({
method: 'POST',
+3 -2
View File
@@ -11,13 +11,14 @@ const localStore = (key, defaultValue) => {
window.g = Vue.reactive({
errorCode: null,
errorMessage: null,
user: null,
wallet: null,
isPublicPage: true,
isUserAuthorized: !!Quasar.Cookies.get('is_lnbits_user_authorized'),
offline: !navigator.onLine,
hasCamera: false,
visibleDrawer: false,
extensions: WINDOW_SETTINGS.EXTENSIONS,
user: null,
wallet: {},
fiatBalance: 0,
exchangeRate: 0,
fiatTracking: false,
+2 -1
View File
@@ -33,7 +33,8 @@ const routes = [
{
path: '/wallet',
redirect: to => {
const walletId = window.g?.lastActiveWallet || window.user?.wallets[0].id
const walletId =
window.g?.lastActiveWallet || window.g?.user?.wallets[0].id
return `/wallet/${to.query.wal || walletId || 'default'}`
}
},
+17 -7
View File
@@ -86,7 +86,7 @@ window.PageHome = {
this.password,
this.passwordRepeat
)
window.location.href = '/wallet'
this.refreshAuthUser()
} catch (e) {
LNbits.utils.notifyApiError(e)
}
@@ -98,7 +98,7 @@ window.PageHome = {
this.password,
this.passwordRepeat
)
window.location.href = '/wallet'
this.refreshAuthUser()
} catch (e) {
LNbits.utils.notifyApiError(e)
}
@@ -106,7 +106,7 @@ window.PageHome = {
async login() {
try {
await LNbits.api.login(this.username, this.password)
window.location.href = '/wallet'
this.refreshAuthUser()
} catch (e) {
LNbits.utils.notifyApiError(e)
}
@@ -114,8 +114,18 @@ window.PageHome = {
async loginUsr() {
try {
await LNbits.api.loginUsr(this.usr)
this.usr = ''
window.location.href = '/wallet'
this.refreshAuthUser()
} catch (e) {
console.warn(e)
LNbits.utils.notifyApiError(e)
}
},
async refreshAuthUser() {
try {
const res = await LNbits.api.getAuthUser()
this.g.user = LNbits.map.user(res.data)
this.g.isPublicPage = false
this.$router.push(`/wallet/${this.g.user.wallets[0].id}`)
} catch (e) {
console.warn(e)
LNbits.utils.notifyApiError(e)
@@ -123,7 +133,7 @@ window.PageHome = {
},
createWallet() {
LNbits.api.createAccount(this.walletName).then(res => {
window.location = '/wallet?usr=' + res.data.user + '&wal=' + res.data.id
this.$router.push(`/wallet/${res.data.id}`)
})
},
processing() {
@@ -136,7 +146,7 @@ window.PageHome = {
},
created() {
if (this.g.isUserAuthorized) {
window.location.href = '/wallet'
return this.refreshAuthUser()
}
const urlParams = new URLSearchParams(window.location.search)
this.reset_key = urlParams.get('reset_key')
+1
View File
@@ -39,6 +39,7 @@ window.windowMixin = {
}
},
paymentEvents() {
if (!this.g.user) return
let timeout
this.g.user.wallets.forEach(wallet => {
if (!this.g.walletEventListeners.includes(wallet.id)) {