You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried using the unstable_update and to customly rewrite the session after the email verification at the route but it does not
seem to work
`import { auth, unstable_update } from "@/auth"; // Correctly import unstable_update
import User from "@/utils/db/models/user.model";
import { NextResponse } from "next/server";
import dbConnect from "@/utils/db/dbConnect";
export async function GET(request) {
try {
const { searchParams } = new URL(request.url);
const token = searchParams.get('token');
console.log("token", token);
const session = await auth();
if (!session) {
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
}
await dbConnect();
const userId = session.user.id;
const user = await User.findById(userId);
if (!user) {
return NextResponse.json({ message: "User not found" }, { status: 404 });
}
const currentTime = new Date().getTime();
if (token === user.verificationToken && currentTime < user.verificationTokenExpiry) {
user.isVerified = true;
await user.save();
// Update the session and token with the new isVerified status
await unstable_update({ ...session, user: { ...session.user, isVerified: true } });
console.log("Route Session", session.user);
return NextResponse.json({ message: "Verification successful" });
}
return NextResponse.json({ message: "Verification failed" }, { status: 400 });
here is my protected route
`import { auth } from "@/auth";
import React from "react";
import SignOutButton from "../auth/components/SignOut";
import { redirect } from "next/navigation";
The session should get updated and I should be able to access the protected route.
The text was updated successfully, but these errors were encountered:
Ali-Raza764
added
bug
Something isn't working
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
labels
Jun 2, 2024
Environment
System: OS: Windows 10 10.0.19045 CPU: (4) x64 Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz Memory: 2.39 GB / 7.92 GB Binaries: Node: 21.5.0 - C:\Program Files\nodejs\node.EXE npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Chromium (123.0.2420.97) Internet Explorer: 11.0.19041.4355 npmPackages: next: 14.2.3 => 14.2.3 react: ^18 => 18.3.1
Reproduction URL
https://github.com/Ali-Raza764/next-auth-tookit
Describe the issue
I have tried using the unstable_update and to customly rewrite the session after the email verification at the route but it does not
seem to work
`import { auth, unstable_update } from "@/auth"; // Correctly import unstable_update
import User from "@/utils/db/models/user.model";
import { NextResponse } from "next/server";
import dbConnect from "@/utils/db/dbConnect";
export async function GET(request) {
try {
const { searchParams } = new URL(request.url);
const token = searchParams.get('token');
console.log("token", token);
} catch (error) {
console.error("Error verifying token:", error);
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
}
}`
here is my protected route
`import { auth } from "@/auth";
import React from "react";
import SignOutButton from "../auth/components/SignOut";
import { redirect } from "next/navigation";
const Protected = async () => {
const session = await auth();
console.log(session);
if (!session.user.isVerified) {
redirect("/auth/verify");
}
return (
{JSON.stringify(session)}
);
};
export default Protected; `
How to reproduce
npm install
npm run dev
Expected behavior
The session should get updated and I should be able to access the protected route.
The text was updated successfully, but these errors were encountered: