Revaycolizer
Revaycolizer
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/8/2023 in #questions
Football live Stream Package
I'll try it
8 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/8/2023 in #questions
Football live Stream Package
How can I get it's API keys?
8 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/8/2023 in #questions
Football live Stream Package
Thanks let me try it
8 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/4/2023 in #questions
Error:localhost redirected too many times
Thanks fixed it already
4 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/5/2023 in #questions
Some of the conditions are omitted in middleware
Fixed already
6 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/5/2023 in #questions
Implementing Middleware
Fixed
3 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 9/2/2023 in #questions
Implementing get Request with Prisma
export async function GET(req: Request, res: NextResponse) {

const member = await redis.get("user")

const useri = JSON.stringify(member)

const usr = JSON.parse(useri)

if(!usr || !member){
return new Response("No user found", {status:404})
}

try {

const user = await prisma.user.findFirst({
where:{
email: usr.email,
ustate: "NON_BLOCKED",
},
select:{
email:true,
role:true,
image:true,
name:true,
}
})

return NextResponse.json(user);

} catch (error) {
console.error("Error retrieving user token:", error);
return new NextResponse("Internal Error", { status: 500 });
}
}
export async function GET(req: Request, res: NextResponse) {

const member = await redis.get("user")

const useri = JSON.stringify(member)

const usr = JSON.parse(useri)

if(!usr || !member){
return new Response("No user found", {status:404})
}

try {

const user = await prisma.user.findFirst({
where:{
email: usr.email,
ustate: "NON_BLOCKED",
},
select:{
email:true,
role:true,
image:true,
name:true,
}
})

return NextResponse.json(user);

} catch (error) {
console.error("Error retrieving user token:", error);
return new NextResponse("Internal Error", { status: 500 });
}
}
3 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
@xchristoph the comparison works thanks
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
I once used it but when tried consuming the API in for login in another frameworks it didn't work out
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
Next-auth only accessible in Nextjs
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
Thanks let me check it
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
Then what is the best idea as I want to implement authentication which can be used in both platforms
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
As the user input is hashed then the hashed value is compared with the hashed Password in the database
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
I compared the hash
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
import { NextResponse,type NextRequest } from "next/server";
import prisma from "@/prisma/client";
import {Redis} from "@upstash/redis"
import bcrypt from "bcrypt";


const redis = Redis.fromEnv();

export async function POST(req: NextRequest, res: NextResponse) {
try {
const body = await req.json();
const { email, password } = body;

console.time()

if (!email || !password) {
return new NextResponse("Email and password are required", { status: 400 });
}

const user = await prisma.user.findFirst({
where: {
email: email as string,
role: "ADMIN",
ustate:"NON_BLOCKED",
}, select: {
id: true,
email: true,
name: true,
image: true,
role:true,
hashedPassword:true
},
});

if (!user || !user.hashedPassword) {
return new NextResponse("User not found", { status: 404 });
}

const Password = await bcrypt.hash(password, 12);

console.log

const passwordMatch = await bcrypt.compare(Password, user.hashedPassword);

if (!passwordMatch) {
return new NextResponse("Invalid credentials", { status: 401 });
}

const member = await redis.set("user",user)
console.log(member)

const response = {
message: "Authenticated!",
};

console.timeEnd()

return new Response(JSON.stringify(response), {
status: 200,
});


} catch (error) {
console.error("Error fetching user:", error);
return new NextResponse("Internal Error", { status: 500 });
}
}

import { NextResponse,type NextRequest } from "next/server";
import prisma from "@/prisma/client";
import {Redis} from "@upstash/redis"
import bcrypt from "bcrypt";


const redis = Redis.fromEnv();

export async function POST(req: NextRequest, res: NextResponse) {
try {
const body = await req.json();
const { email, password } = body;

console.time()

if (!email || !password) {
return new NextResponse("Email and password are required", { status: 400 });
}

const user = await prisma.user.findFirst({
where: {
email: email as string,
role: "ADMIN",
ustate:"NON_BLOCKED",
}, select: {
id: true,
email: true,
name: true,
image: true,
role:true,
hashedPassword:true
},
});

if (!user || !user.hashedPassword) {
return new NextResponse("User not found", { status: 404 });
}

const Password = await bcrypt.hash(password, 12);

console.log

const passwordMatch = await bcrypt.compare(Password, user.hashedPassword);

if (!passwordMatch) {
return new NextResponse("Invalid credentials", { status: 401 });
}

const member = await redis.set("user",user)
console.log(member)

const response = {
message: "Authenticated!",
};

console.timeEnd()

return new Response(JSON.stringify(response), {
status: 200,
});


} catch (error) {
console.error("Error fetching user:", error);
return new NextResponse("Internal Error", { status: 500 });
}
}

20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/31/2023 in #questions
Implementing login with Prisma
I tried but didn't work for me as bycrpt produces different values
20 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/30/2023 in #questions
Vercel Caching Data during Deployment
🔥🔥I'm gonna try
9 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/30/2023 in #questions
Vercel Caching Data during Deployment
Thanks let me try it although never used it
9 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/30/2023 in #questions
Vercel Caching Data during Deployment
To deploy?
9 replies
TTCTheo's Typesafe Cult
Created by Revaycolizer on 8/23/2023 in #questions
Storing and retrieving cookie
Wow Redis works like a charm
23 replies