
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
- Trying to connect platform
I'm stuck here for about 1 day how can I connect my platform i am trying to connect localhost in react
- Login without email or phone number
I'm making a web app targeted towards users who are very tech illiterate, so a lot of them won't even have emails. I know that the only two "identifiers" for a...
- Password Recovery link takes upwards of ...
Hello. I am having this issue above. Is there a way to make this faster? I created this project a while back when appwrite only supported Frankfurt servers. Wil...
