Skip to content

Commit

Permalink
fix: update function for magicURLs
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-nowicki committed Jul 15, 2024
1 parent 7209037 commit ab30d35
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions functions/userAuth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

const { ID } = require('appwrite');
const sdk = require('node-appwrite');
const { ID, Query } = require('appwrite');
const sdk, = require('node-appwrite');

/**
* creates a new user record in the User collection
Expand All @@ -22,6 +22,17 @@ const user = async ({ req, res }) => {
.setProject(process.env.PROJECT_ID) // Your project ID
.setKey(process.env.X_Appwrite_Key); // Your secret API key

// check if user exists
const user = await databases.listDocuments(
process.env.DATABASE_ID,
process.env.COLLECTION_USERS_ID,
[Query.equal('$id', req.body['$id'])],
);

if (user.documents.length > 0) {
return res.json({ msg: 'User already exists!' });
}

// create a new user
if (req.method === 'POST' && req.body.email && req.body['$id']) {
await databases.createDocument(
Expand Down

0 comments on commit ab30d35

Please sign in to comment.