GithubHelp home page GithubHelp logo

casdoor / nextjs-auth Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 3.0 277 KB

Next.js Authentication based on Casdoor, live demo: https://nextjs-auth.casdoor.org

Home Page: https://nextjs.org

License: Apache License 2.0

JavaScript 95.32% CSS 4.68%
auth authentication casbin casdoor next nextjs nextjs13 cas iam oauth oidc saml sso example middleware plugin react reactjs ssr

nextjs-auth's Introduction

nextjs-auth

A Next.js example for Casdoor SSO.

Live demo: https://nextjs-auth.casdoor.org

Demo video

Login

Configuration

The default config.js points to the Casdoor demo site. Change it to your own Casdoor:

const sdkConfig = {
  serverUrl: "https://door.casdoor.com",
  clientId: "294b09fbc17f95daf2fe",
  clientSecret: "dd8982f7046ccba1bbd7851d5c1ece4e52bf039d",
  organizationName: "casbin",
  appName: "app-vue-python-example",
  redirectPath: "/callback",
}

export default sdkConfig;

Getting started

run the development server:

yarn dev

Open http://localhost:3000 with your browser to see the result.

nextjs-auth's People

Contributors

hsluoyz avatar samysf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nextjs-auth's Issues

How to work with next-intl?

Hi guys, I have a question about the demo project.
In the middleware.ts.

const protectedRoutes = ["/profile"];

export default function middleware(req) {
  const casdoorUserCookie = req.cookies.get("casdoorUser");
  const isAuthenticated = casdoorUserCookie ? true : false;

  if (!isAuthenticated && protectedRoutes.includes(req.nextUrl.pathname)) {
    return NextResponse.redirect(new URL('/login', req.url))
  }
}

variable req.nextUrl.pathname may have some locale prefix if your import next-intl/ package in your project to support multi-language. So the proteced path can't be matched in this situation. How to resolve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.