Revisions for untitled paste

View the changes made to this paste.

unlisted ⁨1⁩ ⁨file⁩ 2023-08-12 09:19:38 UTC

auth.ts

@@ -0,0 +1,32 @@

+ async authorize(credentials) {
+        
+        if (!credentials?.username || !credentials?.password || !credentials?.email){
+          return null
+        }
+        const VerfiedUser = await prisma.user.findUnique({
+          where:{
+            username: credentials?.email,
+          }
+        })
+
+        if (VerfiedUser){
+          return VerfiedUser
+        }
+
+        const hash = await bcrypt.hash(credentials?.password ,10)
+       
+        const NewUser = await prisma.user.create({
+          data:{
+            username: credentials?.username,
+            password:hash
+          }
+        })
+
+        if (NewUser){
+          return NewUser
+        }
+       
+       
+        // Return null if user data could not be retrieved
+        return null
+      }
\ No newline at end of file