Hello, I am trying to implement a middleware to protect the routes in my website. However it is not working as it is throwing a AppwriteException: User (role: guests) missing scope (account) at Generator.next (<anonymous>).
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { Client, Account } from "appwrite";
import { appwriteConfig } from "@/lib/appwrite/config";
export async function middleware(request: NextRequest) {
const client = new Client()
.setProject(appwriteConfig.projectId);
const account = new Account(client);
let isAuthenticated;
isAuthenticated = await account.get();
if (!isAuthenticated && request.nextUrl.pathname === "/home" ) {
console.log(isAuthenticated);
const signInUrl = new URL('/sign-in', request.url);
return NextResponse.redirect(signInUrl);
}
return NextResponse.next();
}
For now I have the code so that the user can't acess the home page if they have not logged in
Recommended threads
- Dashboard permissions
I am setting up a new Database and there will be different authenticated users that need to only create, read, update and delete only their own records. In the...
- AppwriteException: general_resource_bloc...
I can't access the database from my app or the Appwrite console dashboard. It's saying, '401 Access to this resource is blocked.'
- Unreliable log in (Can't find logs)
Some users can't log in, AppWrites return that they enter an incorrect password/mail, while we are sure they are correct. The error occurs on IOS with a Flutte...