Refactor authentication handling and update loading components
The authentication handling logic in the middleware.ts file was refactored to improve clarity and control flow. In addition, the loading component, previously located in the main app directory, has been deleted and recreated specifically for admin use. The list of private path prefixes has been updated in the use-auth-change-listener.ts file to reflect these changes.
This commit is contained in:
3
apps/web/app/admin/loading.tsx
Normal file
3
apps/web/app/admin/loading.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
import { GlobalLoader } from '@kit/ui/global-loader';
|
||||
|
||||
export default GlobalLoader;
|
||||
@@ -1,5 +0,0 @@
|
||||
import { GlobalLoader } from '@kit/ui/global-loader';
|
||||
|
||||
export default function Loading() {
|
||||
return <GlobalLoader displaySpinner={false} />;
|
||||
}
|
||||
@@ -135,12 +135,15 @@ function getPatterns() {
|
||||
},
|
||||
{
|
||||
pattern: new URLPattern({ pathname: '/auth*' }),
|
||||
handler: async (req: NextRequest, res: NextResponse) => {
|
||||
handler: async (
|
||||
req: NextRequest,
|
||||
res: NextResponse,
|
||||
userResponse: UserResponse,
|
||||
) => {
|
||||
const supabase = createMiddlewareClient(req, res);
|
||||
const { data: user, error } = await supabase.auth.getUser();
|
||||
|
||||
// the user is logged out, so we don't need to do anything
|
||||
if (error) {
|
||||
if (!userResponse.data) {
|
||||
await supabase.auth.signOut();
|
||||
|
||||
return;
|
||||
@@ -151,7 +154,7 @@ function getPatterns() {
|
||||
|
||||
// If user is logged in and does not need to verify MFA,
|
||||
// redirect to home page.
|
||||
if (user && !isVerifyMfa) {
|
||||
if (!isVerifyMfa) {
|
||||
return NextResponse.redirect(
|
||||
new URL(pathsConfig.app.home, req.nextUrl.origin).href,
|
||||
);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { useRevalidateUserSession, useUserSession } from './use-user-session';
|
||||
* @name PRIVATE_PATH_PREFIXES
|
||||
* @description A list of private path prefixes
|
||||
*/
|
||||
const PRIVATE_PATH_PREFIXES = ['/home', '/admin', '/update-password'];
|
||||
const PRIVATE_PATH_PREFIXES = ['/home', '/admin', '/join', '/update-password'];
|
||||
|
||||
/**
|
||||
* @name useAuthChangeListener
|
||||
|
||||
Reference in New Issue
Block a user