Hi I am using next js 14 with aws amplify for authentication. I guess aws amplify had some updates so you will be not up to date. I am using the method getCurrentUser() to get the session of the current user.
In my middleware I want only allow access to / route for unauthenticated access. If the user is authenticated I would allow any route which is available.
The method getCurrentUser will give me the following back if i am unauthenticated
Promise { <state>: "pending" }
<state>: "rejected"
<reason>: UserUnAuthenticatedException: User needs to be authenticated to call this API.
columnNumber: 9
constructor: class AuthError { constructor(params) }
message: "User needs to be authenticated to call this API."
name: "UserUnAuthenticatedException"
recoverySuggestion: "Sign in before calling this API again."
and this when I am authenticated
Promise { <state>: "pending" }
<state>: "fulfilled"
<value>: Object { username: "73840872-f081-7095-b89f-2095df12f574", userId: "73840872-f081-7095-b89f-2095df12f574", signInDetails: {…} }
signInDetails: Object { loginId: "a@gmail.com", authFlowType: "USER_SRP_AUTH" }
authFlowType: "USER_SRP_AUTH"
loginId: "a@gmail.com"
<prototype>: Object { … }
userId: "73840872-f081-7095-b89f-2095df12f574"
I would like to extend my middleware with the protected routes etc.
import { getCurrentUser } from 'aws-amplify/auth';
import createMiddleware from 'next-intl/middleware';
import { locales, localePrefix } from '../i18n/navigation';
export default createMiddleware({
defaultLocale: 'nl',
localePrefix,
locales,
localeDetection: true,
});
export const config = {
// Skip all paths that should not be internationalized. This example skips
// certain folders and all pathnames with a dot (e.g. favicon.ico)
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
};
Please help me how to do it and focus on how to protect the routes the amplify part I will take care of