-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6327acf
commit f9b0fe1
Showing
4 changed files
with
18 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,14 @@ import { AccountDisplayName } from "../type/accountDisplayName.ts"; | |
import { getAccountByCodeResolve } from "../query/accountByCode.ts"; | ||
import { TotpKeyId } from "../type/id.ts"; | ||
import { CreateAccountResult } from "../type/createAccountResult.ts"; | ||
import { TotpSecret } from "../type/totpSecret.ts"; | ||
import { TotpCode } from "../type/totpCode.ts"; | ||
import { TOTP } from "https://deno.land/x/[email protected]/totp.ts"; | ||
import { | ||
Account, | ||
cacheAccountByCodeKey, | ||
entityKey, | ||
temporaryTotpKeyKey, | ||
TemporaryTotpKeyValue, | ||
} from "../kv.ts"; | ||
|
||
export const createAccount: g.GraphQLFieldConfig< | ||
|
@@ -56,9 +56,10 @@ export const createAccount: g.GraphQLFieldConfig< | |
accountCode: args.accountCode, | ||
}; | ||
} | ||
const totpKey = | ||
(await denoKv.get<TotpSecret>(["temporaryTotpKey", args.totpKeyId])) | ||
.value; | ||
const totpKey = (await denoKv.get<TemporaryTotpKeyValue>( | ||
temporaryTotpKeyKey(args.totpKeyId), | ||
)) | ||
.value; | ||
if (totpKey === null) { | ||
return { | ||
__typename: "CreateAccountNotFoundTotpKeyId", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { TOTP } from "https://deno.land/x/[email protected]/mod.ts"; | |
import { TotpKeyAndId } from "../type/totpKeyAndId.ts"; | ||
import { totpKeyIdIdFrom } from "../type/id.ts"; | ||
import { totpSecretFrom } from "../type/totpSecret.ts"; | ||
import { temporaryTotpKeyKey, TemporaryTotpKeyValue } from "../kv.ts"; | ||
|
||
export const createTotpKey: g.GraphQLFieldConfig< | ||
void, | ||
|
@@ -17,11 +18,15 @@ export const createTotpKey: g.GraphQLFieldConfig< | |
await TOTP.exportKey(await TOTP.generateKey(32)), | ||
); | ||
const id = totpKeyIdIdFrom(crypto.randomUUID().replaceAll("-", "")); | ||
await denoKv.set(["temporaryTotpKey", id], key, { | ||
expireIn: | ||
// 30min | ||
30 * 60 * 1000, | ||
}); | ||
await denoKv.set( | ||
temporaryTotpKeyKey(id), | ||
key satisfies TemporaryTotpKeyValue, | ||
{ | ||
expireIn: | ||
// 30min | ||
30 * 60 * 1000, | ||
}, | ||
); | ||
return { | ||
id, | ||
secret: key, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters