Coder Social home page Coder Social logo

ivandotv / nextjs-client-signin-logic Goto Github PK

View Code? Open in Web Editor NEW
128.0 1.0 31.0 212 KB

Example of implementing client sign-in flow with Next.js and protecting static pages from unauthorized access.

Home Page: https://static-page-login-example.vercel.app/

JavaScript 13.12% TypeScript 73.63% CSS 13.25%
nextjs nextjs-example

nextjs-client-signin-logic's Introduction

nextjs-client-signin-logic's People

Contributors

ivandotv avatar raja-poudel avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nextjs-client-signin-logic's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • next 12.3.4
  • react 17.0.2
  • react-dom 17.0.2
  • @next/eslint-plugin-next ^12.0.9
  • @types/node ^17.0.13
  • @types/react ^17.0.38
  • @typescript-eslint/eslint-plugin ^5.10.2
  • @typescript-eslint/parser ^5.10.2
  • eslint ^8.8.0
  • eslint-config-prettier ^8.3.0
  • eslint-plugin-prettier ^4.0.0
  • eslint-plugin-react ^7.28.0
  • eslint-plugin-react-hooks ^4.3.0
  • prettier ^2.5.1
  • typescript ^4.5.5

  • Check this box to trigger a request for Renovate to run again on this repository

Redirect back to public page

Hello Ivan

I found this package very useful and integrated it into my application. Very nice work :)

I had one small issue: If I'm on a public page then sign-in, I'm not returned back to that page. It only works for private pages. I fixed this by wrapping all pages in <AuthGuard> regardless of whether they're public or private, then in AuthGuard.tsx I changed the useEffect function to look like this:

    useEffect(() => {
        if (!initializing) {
            //auth is initialized and there is no user
            if (!user) {
                if (!skipRedirect) {
                    // Set redirect unless it's a special route
                    // for which it should be skipped.
                    setRedirect(router.route)
                }
                if (requireAuth) {
                    router.push("/signin")      
                }
            }
        }
    }, [initializing, router, user, setRedirect])

This requires an extra property for the page called skipRedirect, which doesn't need to be set except for pages which you don't want to redirect back to โ€• such as the sign-in page.

I haven't got time to do a PR but I think this would be a nice addition.

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.