Skip to content

Commit

Permalink
Magic link authentication
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Hava <[email protected]>
  • Loading branch information
devpikachu committed Oct 24, 2023
1 parent 1ba51c4 commit aad6f56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 20 additions & 3 deletions services/authAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,37 @@ export default function XataAdapter(client, options = {}) {
const xata = getXataClient();

const createdToken = await xata.db.tokens.create({
name: identifier,
identifier: identifier,
value: token,
expiresAt: expires
});

return {
identifier: createdToken.name,
identifier: createdToken.identifier,
token: createdToken.value,
expires: createdToken.expiresAt
}
},

async useVerificationToken({identifier, token}) {
throw new Error("Not implemented");
console.log("useVerificationToken: using verification token", identifier, token);

const xata = getXataClient();

const tokenRecord = await xata.db.tokens.filter("identifier", identifier).getFirst();

if (!tokenRecord) {
console.log("useVerificationToken: token not found");
return null;
}

await xata.db.tokens.delete(tokenRecord.id);

return {
identifier: tokenRecord.identifier,
token: tokenRecord.value,
expires: tokenRecord.expiresAt
}
},
};
}
6 changes: 2 additions & 4 deletions services/xata.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aad6f56

Please sign in to comment.