This commit is contained in:
hatim boufnichel 2024-04-09 22:37:13 +02:00
parent a8c30afcdd
commit 139cf1d3c9
2 changed files with 23 additions and 32 deletions

View file

@ -192,7 +192,7 @@ export default class {
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier)
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override)
}
async RequestNsecLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest): Promise<Types.RequestNPubLinkingTokenResponse> {
async RequestNPubLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest): Promise<Types.RequestNPubLinkingTokenResponse> {
const app = await this.storage.applicationStorage.GetApplication(appId);
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier);
if (Array.from(this.nPubLinkingTokens.values()).find(t => t.serialId === user.serial_id)) {
@ -208,17 +208,14 @@ export default class {
async LinkNpubThroughToken(appId: string, appUserId: string, req: Types.LinkNPubThroughTokenRequest): Promise<void> {
async LinkNpubThroughToken(ctx: Types.UserContext, req: Types.LinkNPubThroughTokenRequest): Promise<void> {
const { app_id: appId, app_user_id: appUserId } = ctx
const app = await this.storage.applicationStorage.GetApplication(appId)
const appUser = await this.storage.applicationStorage.GetApplicationUser(app, appUserId)
/*
needs to be a db tx, otherwise gets foreign constraint error when deleting baseUser after
applicationUser, and unique constatin when giving targetted applicationUser the npub
*/
this.storage.DB.transaction(async tx => {
this.storage.txQueue.PushToQueue({
dbTx: true,
exec: async tx => {
await this.storage.applicationStorage.RemoveApplicationUserAndBaseUser(appUser, tx);
const entry = this.nPubLinkingTokens.get(req.token)
if (entry && entry.expiry > Date.now()) {
const copy = { ...entry }
@ -231,9 +228,7 @@ export default class {
} else {
throw new Error("Token invalid or expired")
}
})
}
})
}
}

View file

@ -205,7 +205,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
user_identifier_CustomCheck: userIdentifier => userIdentifier !== '',
})
if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.RequestNsecLinkingToken(ctx.app_id, req)
return mainHandler.applicationManager.RequestNPubLinkingToken(ctx.app_id, req)
},
LinkNPubThroughToken: async ({ ctx, req }) => {
const err = Types.LinkNPubThroughTokenRequestValidate(req, {
@ -213,11 +213,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
token_CustomCheck: token => token !== ''
})
if (err != null) throw new Error(err.message)
return mainHandler.applicationManager.LinkNpubThroughToken(ctx.app_id, ctx.app_user_id, req)
return mainHandler.applicationManager.LinkNpubThroughToken(ctx, req)
}
}
}