facing error in middleware.js
Unanswered
Spotted Rail posted this in #help-forum
Spotted RailOP
TypeError: Cannot read properties of undefined (reading 'substring')
node_modules\oidc-token-hash\lib\shake256.js (3:1)
node_modules\oidc-token-hash\lib\shake256.js (3:1)
3 Replies
Spotted RailOP
middleware.js
import NextAuth from 'next-auth';
import { authConfig } from './auth.config';
export default NextAuth(authConfig).auth;
export const config = {
matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
};auth.config.js
export const authConfig = {
pages: {
signIn: '/signin',
},
callbacks: {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnDashboard = nextUrl && nextUrl.pathname.startsWith('/dashboard');
if (isOnDashboard) {
if (isLoggedIn) return true;
return false; // Redirect unauthenticated users to login page
} else if (isLoggedIn) {
return Response.redirect(new URL('/dashboard', nextUrl));
}
return true;
},
},
}Spotted RailOP
This is fixed, I had to install next-auth@beta