PingGhostOriginal post
Rank 1: Thread
Hello fellas, I am trying to use Appwrite with nextjs middleware to check the auth status.
giving a weird error
Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.
my middleware
import { NextRequest, NextResponse } from 'next/server'
import { getLoggedInUser } from './lib/auth'
// 1. Specify protected and public routes
const protectedRoutes = ['/dashboard']
const publicRoutes = ['/login', '/signup', '/']
export default async function middleware(req: NextRequest) {
// 2. Check if the current route is protected or public
const path = req.nextUrl.pathname
const isProtectedRoute = protectedRoutes.includes(path)
const isPublicRoute = publicRoutes.includes(path)
// 3. Decrypt the session from the cookie
const session = await getLoggedInUser()
// 5. Redirect to /login if the user is not authenticated
if (isProtectedRoute && !session?.$id) {
return NextResponse.redirect(new URL('/login', req.nextUrl))
}
// 6. Redirect to /dashboard if the user is authenticated
if (
isPublicRoute &&
session?.$id &&
!req.nextUrl.pathname.startsWith('/dashboard')
) {
return NextResponse.redirect(new URL('/dashboard', req.nextUrl))
}
return NextResponse.next()
}
// Routes Middleware should not run on
export const config = {
matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
}```
Summary
Appwrite SDK is being used with Next.js middleware for authentication, but encountering an UnhandledSchemeError related to "node:stream" in the Webpack build process.
To fix this error, consider using an additional plugin to handle "node:" URIs.