Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Improvement: URL Path Standardization: Change /signin and /signup to /sign-in and /sign-up #577

Closed
2 tasks done
SinghAstra opened this issue Nov 7, 2024 · 2 comments

Comments

@SinghAstra
Copy link
Contributor

πŸ“œ Description

Overview

Currently, the project uses /signin and /signup URL paths, which deviate from the common web convention of using hyphenated paths (/sign-in and /sign-up). This inconsistency affects readability and doesn't follow URL best practices.

Current Implementation

The paths are defined in path.config.ts but are also hardcoded in various places throughout the codebase, including middleware.ts:

// path.config.ts
const APP_PATHS = {
  SIGNIN: '/signin',
  SIGNUP: '/signup',
  // ...
};

// middleware.ts
if (!token && pathname === '/create') {
  return NextResponse.redirect(new URL('/signin', req.url));
}

Why Change?

  1. Readability: Hyphenated URLs are more readable when containing multiple words
  2. Convention: Most modern web applications use hyphenated paths for multi-word routes
  3. SEO: Search engines better understand hyphenated URLs
  4. Consistency: Follows established web development best practices

Required Changes

1. Update path.config.ts:

const APP_PATHS = {
  SIGN_IN: '/sign-in',  // Changed from SIGNIN: '/signin'
  SIGN_UP: '/sign-up',  // Changed from SIGNUP: '/signup'
  // ...
};

2. Search and Replace

Files that need to be checked and updated:

  • middleware.ts
  • May be auth too have not checked all the files yet

3. Add URL Redirects

To maintain backward compatibility, implement redirects from old paths to new ones:

  • /signin β†’ /sign-in
  • /signup β†’ /sign-up

πŸ‘Ÿ Reproduction steps

No response

πŸ‘ Expected behavior

No response

πŸ“ƒ Provide any additional context for the Bug.

No response

πŸ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Contributing Guidelines?

@SinghAstra
Copy link
Contributor Author

Even the User Role is hardcoded I think that needs to be fixed too
Is this worth creating a pr @VineeTagarwaL-code

@SinghAstra
Copy link
Contributor Author

Suggested Improvement :

// src/middleware.ts
import { getToken } from "next-auth/jwt";
import { NextRequest, NextResponse } from "next/server";
import { ADMIN_ROLE, HR_ROLE, USER_ROLE } from "./config/app.config";
import APP_PATHS from "./config/path.config";

export async function middleware(req: NextRequest) {
  const token = await getToken({ req, secret: process.env.NEXT_AUTH_SECRET });
  console.log("token is ", token);
  const { pathname } = new URL(req.url);
  if (!token && pathname === APP_PATHS.POST_JOB) {
    return NextResponse.redirect(new URL(APP_PATHS.SIGN_IN, req.url));
  }
  if (
    pathname === APP_PATHS.POST_JOB &&
    token?.role !== ADMIN_ROLE &&
    token?.role !== HR_ROLE
  ) {
    return NextResponse.redirect(new URL(APP_PATHS.HOME, req.url));
  }
  if (
    pathname !== APP_PATHS.CREATE_PROFILE &&
    token?.role === USER_ROLE &&
    !token.onBoard
  ) {
    return NextResponse.redirect(new URL(APP_PATHS.CREATE_PROFILE, req.url));
  }
  return NextResponse.next();
}

export const config = {
  matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
  • New Paths Needs to be added too.
const APP_PATHS = {
  HOME: "/",
  POST_JOB: "/create",
  CREATE_PROFILE: "/create-profile",
  MANAGE_JOBS: "/manage/jobs",
  SIGN_IN: "/sign-in",
  SIGN_UP: "/sign-up",
  FORGOT_PASSWORD: "/forgot-password",
  JOBS: "/jobs",
  CONTACT_US: "mailto:singhisabhaypratap@gmail.com",
};
export default APP_PATHS;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant