-
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.
π server: implement passkey authentication
- Loading branch information
1 parent
2feb813
commit 37dd24f
Showing
12 changed files
with
185 additions
and
102 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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
import { authenticated } from "../utils/auth.js"; | ||
import { createCard, getCardsByUserID } from "../utils/card.js"; | ||
import allowCors from "../utils/cors.js"; | ||
import { getUserByCredentialID } from "../utils/user.js"; | ||
|
||
async function handler(request: VercelRequest, response: VercelResponse, credentialID: string) { | ||
const user = await getUserByCredentialID(credentialID); | ||
if (!user) { | ||
response.status(404).end("User not found"); | ||
return; | ||
} | ||
if (request.method === "POST") { | ||
try { | ||
const card = await createCard({ | ||
user_id: user.id, | ||
card_type: "VIRTUAL", | ||
affinity_group_id: "afg-2VfIFzzjDX9eRD2VVgmKnB6YmWm", // TODO use env. note: we'll probably use the same affinity group for all cards | ||
}); | ||
response.status(200).json(card); | ||
} catch (error) { | ||
response.status(400).end(error instanceof Error ? error.message : "There was an error"); | ||
} | ||
} else if (request.method === "GET") { | ||
const cards = await getCardsByUserID(user.id); | ||
response.status(200).json(cards); | ||
} | ||
} | ||
export default allowCors(authenticated(handler)); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { VercelRequest, VercelResponse } from "@vercel/node"; | ||
|
||
import { authenticated } from "../utils/auth.js"; | ||
import allowCors from "../utils/cors.js"; | ||
import type { CreateUserForm } from "../utils/types.js"; | ||
import { createUser, getUserByCredentialID } from "../utils/user.js"; | ||
|
||
async function handler(request: VercelRequest, response: VercelResponse, credentialID: string) { | ||
if (request.method === "POST") { | ||
try { | ||
const body = request.body as CreateUserForm; // TODO validate request body | ||
const user = await createUser({ | ||
...body, | ||
operation_country: "MEX", // TODO only for sandbox. For prod will be "PER" | ||
email: `${credentialID}@exactly.account`, | ||
}); | ||
response.status(200).json(user); | ||
} catch (error) { | ||
response.status(400).end(error instanceof Error ? error.message : "Unknown error"); | ||
} | ||
} else if (request.method === "GET") { | ||
const user = await getUserByCredentialID(credentialID); | ||
if (user) { | ||
response.status(200).json(user); | ||
} else { | ||
response.status(404).end("User not found"); | ||
} | ||
} | ||
} | ||
|
||
export default allowCors(authenticated(handler)); |
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
Oops, something went wrong.