fix: missing account id in response
This commit is contained in:
parent
c17aaf25cb
commit
7dcb7f30af
@ -0,0 +1,5 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "TerminalAuthRequest" ADD COLUMN "responseAccountId" TEXT;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "TerminalAuthRequest" ADD CONSTRAINT "TerminalAuthRequest_responseAccountId_fkey" FOREIGN KEY ("responseAccountId") REFERENCES "Account"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
@ -27,12 +27,15 @@ model Account {
|
|||||||
Session Session[]
|
Session Session[]
|
||||||
Update Update[]
|
Update Update[]
|
||||||
AccountPushToken AccountPushToken[]
|
AccountPushToken AccountPushToken[]
|
||||||
|
TerminalAuthRequest TerminalAuthRequest[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model TerminalAuthRequest {
|
model TerminalAuthRequest {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
publicKey String @unique
|
publicKey String @unique
|
||||||
response String?
|
response String?
|
||||||
|
responseAccountId String?
|
||||||
|
responseAccount Account? @relation(fields: [responseAccountId], references: [id])
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
@ -188,12 +188,12 @@ export async function startApi() {
|
|||||||
|
|
||||||
const answer = await db.terminalAuthRequest.upsert({
|
const answer = await db.terminalAuthRequest.upsert({
|
||||||
where: { publicKey: privacyKit.encodeHex(publicKey) },
|
where: { publicKey: privacyKit.encodeHex(publicKey) },
|
||||||
update: { updatedAt: new Date() },
|
update: {},
|
||||||
create: { publicKey: privacyKit.encodeHex(publicKey) }
|
create: { publicKey: privacyKit.encodeHex(publicKey) }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (answer.response) {
|
if (answer.response && answer.responseAccountId) {
|
||||||
const token = await tokenGenerator.new({ user: answer.id, extras: { session: answer.id } });
|
const token = await tokenGenerator.new({ user: answer.responseAccountId!, extras: { session: answer.id } });
|
||||||
return reply.send({
|
return reply.send({
|
||||||
state: 'authorized',
|
state: 'authorized',
|
||||||
token: token,
|
token: token,
|
||||||
@ -206,6 +206,7 @@ export async function startApi() {
|
|||||||
|
|
||||||
// Approve auth request
|
// Approve auth request
|
||||||
typed.post('/v1/auth/response', {
|
typed.post('/v1/auth/response', {
|
||||||
|
preHandler: app.authenticate,
|
||||||
schema: {
|
schema: {
|
||||||
body: z.object({
|
body: z.object({
|
||||||
response: z.string(),
|
response: z.string(),
|
||||||
@ -227,7 +228,7 @@ export async function startApi() {
|
|||||||
if (!authRequest.response) {
|
if (!authRequest.response) {
|
||||||
await db.terminalAuthRequest.update({
|
await db.terminalAuthRequest.update({
|
||||||
where: { id: authRequest.id },
|
where: { id: authRequest.id },
|
||||||
data: { response: request.body.response }
|
data: { response: request.body.response, responseAccountId: request.user.id }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return reply.send({ success: true });
|
return reply.send({ success: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user