Skip to content

Commit

Permalink
feat: login D1
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 11, 2024
1 parent 0582571 commit ca4ceec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 7 additions & 3 deletions functions/login/[email]/[hash].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ export const onRequestGet = async context => {
context.params?.hash
) {
console.log('email', context.params.email)


const { results } = await context.env.d1db.prepare(
"SELECT * FROM members WHERE email = ?"
)
.bind(context.params.email)
.all()
return Response.json(results)
}
return new Response.json({ 'err': 'OAuth authorization code not provided' })
return new Response.json({ 'err': 'Authentication' })
}

async function pbkdf2Verify(key, password, hashBits = 512) {
Expand Down
12 changes: 5 additions & 7 deletions functions/register/[org]/[email]/[hash].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ export const onRequestGet = async context => {
) {
console.log('org', context.params.org)
// const kid = crypto.randomUUID()
const { results } = await context.env.trivial_triage.prepare(
"SELECT * FROM members WHERE email = ?"
)
.bind(context.params.email)
.all()
return Response.json(results)
const info = await db.prepare('INSERT INTO members (orgName, email, passwordhash) VALUES (?1, ?2, ?3)')
.bind(context.params.org, context.params.email, pbkdf2(context.params.hash))
.run()
return Response.json(info)
}
return new Response.json({ 'err': 'OAuth authorization code not provided' })
return new Response.json({ 'err': 'missing properties /register/[org]/[email]/[sha1]' })
}

async function pbkdf2(password, iterations = 1e6, hashBits = 512) {
Expand Down

0 comments on commit ca4ceec

Please sign in to comment.