
Hi guys, can i check if i'm planning to use middleware.ts i'm supposed to use node-appwrite
right? I'm using just the appwrite
one and it doesn't seem to work.
Keeps saying i'm not authenticated while i already am
TL;DR
Developers are experiencing authentication issues when using middleware in NextJS with the 'appwrite' library instead of 'node-appwrite'. It is recommended to use 'node-appwrite' for authentication in middleware.ts.
In addition i've tried
TypeScript
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { appwriteServerAccount } from './lib/server/appwriteServer'
export async function middleware(request: NextRequest) {
if (request.nextUrl.pathname.startsWith('/dashboard')) {
const user = await appwriteServerAccount.get();
console.log(user)
if (!user) {
return NextResponse.redirect(new URL('/login', request.url))
}
}
return NextResponse.next()
}
export const config = {
matcher: ['/dashboard/:path*'],
}
and
TypeScript
import { Account } from 'node-appwrite';
import { Client } from 'node-appwrite';
const appwriteServerClient = new Client();
appwriteServerClient
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID as string)
.setKey(process.env.APPWRITE_SECRET_API_KEY as string);
export const appwriteServerAccount = new Account(appwriteServerClient);
export default appwriteServerClient;
But it still says i'm not authenticated
Recommended threads
- Query params are way too limiting in ter...
I was trying to list rows in a table that do not already exist in another table. I retrieved around 260 row IDs which are 13 characters in length each, and then...
- [Node.js SDK] Bypass 2GB file limit?
Hello. Using either InputFile.fromPath or InputFile.fromBuffer throws this error: File size (2295467305) is greater than 2 GiB Bucket limit etc. is setup corre...
- What Happens When You Add a Custom Domai...
