GithubHelp home page GithubHelp logo

swizec / useauth Goto Github PK

View Code? Open in Web Editor NEW
2.6K 27.0 110.0 11.88 MB

The simplest way to add authentication to your React app. Supports various providers.

Home Page: https://useauth.dev

License: MIT License

TypeScript 98.74% JavaScript 1.26%
react reacthooks auth0 reactjs useauth gatsby nextjs netlify-identity xstate

useauth's Introduction

useAuth

the quickest way to add authentication to your React app

All Contributors Version License: MIT

useAuth.dev

Getting Started

useAuth is designed to be quick to setup. You'll need an account with Auth0 or Netlify Identity and the appropriate access keys.

1. Install the hook

$ yarn add react-use-auth

Downloads from npm, adds to your package.json, etc. You can use npm as well.

2. Install your auth client

useAuth does not install its own authentication clients. Instead they're marked as peer dependencies.

Install auth0-js or netlify-identity-widget depending on what you'd like to use. More coming soon :)

$ yarn add auth0-js

or

$ yarn add netlify-identity-widget

You'll see warnings about missing peer dependencies for the client you aren't using. That's okay.

3. Configure with AuthConfig

useAuth uses an <AuthConfig> component to configure your authentication client. We use XState behind the scenes to manage authentication state for you.

Ensure AuthConfig renders on every page.

With Gatsby, add it to gatsby-browser.js. With NextJS, _app.js is best. You don't need to wrap your component tree, but you can if you prefer. We make sure useAuth doesn't break server-side rendering. ✌️

// gatsby-browser.js
import * as React from "react";
import { navigate } from "gatsby";

import { AuthConfig } from "react-use-auth";
import { Auth0 } from "react-use-auth/auth0";

export const wrapRootElement = ({ element }) => (
    <>
        <AuthConfig
            navigate={navigate}
            authProvider={Auth0}
            params={{
                domain: "useauth.auth0.com",
                clientID: "GjWNFNOHqlino7lQNjBwEywalaYtbIzh"
            }}
        />
        {element}
    </>
);

<AuthConfig> initializes the global XState state machine, sets up an Auth0 client, and validates user sessions on every load. You now have easy access to authentication in your whole app :)

The config options are:

  1. navigate – your navigation function, used for redirects. Tested with Gatsby, NextJS, and React Router. Anything should work.

  2. authProvider – the useAuth interface to your authentication provider.

  3. params – parameters for your authentication provider

useAuth client wrappers provide smart defaults.

More detail on using custom configuration for each client in Use with Auth0, and Use with Netlify Identity. To learn about how this works, go to Create an auth provider

PS: feel free to use my Auth0 domain and clientID to see if useAuth is a good fit for you. That's why they're visible in the code snippet 😊

4. Create the callback page

Auth0 and most other authentication providers use OAuth. That requires redirecting your user to their login form. After login, the provider redirects users back to your app.

You can skip this step with Netlify Identity. It uses an in-page popup.

Any way of creating React pages should work, here's the code I use for Gatsby:

import * as React from "react"
import { useAuth } from "react-use-auth"

const Auth0CallbackPage = () => {
    const { handleAuthentication } = useAuth()
    React.useEffect(() => {
        handleAuthentication()
    }, [handleAuthentication])

    return (
        <h1>
            This is the auth callback page,
            you should be redirected immediately!
        </h1>
    )
}

export default Auth0CallbackPage

The goal is to load a page, briefly show some text, and run the handleAuthentication method from useAuth on page load.

That method will create a cookie in local storage with your user's information and redirect back to homepage. You can pass a postLoginRoute param to redirect to a different page.

Make sure you add <domain>/auth0_callback as a valid callback URL in your Auth0 config.

5. Enjoy useAuth

You're ready to use useAuth for authentication in your React app. 🤘

Here's a login button for example:

const Login = () => {
    const { isAuthenticated, login, logout } = useAuth();

    if (isAuthenticated()) {
        return <Button onClick={logout}>Logout</Button>;
    } else {
        return <Button onClick={login}>Login</Button>;
    }
};

isAuthenticated is a method that checks if the user's cookie is still valid.

login and logout trigger their respective actions.

You can even say hello to your users:

// src/pages/index.js

const IndexPage = () => {
  const { isAuthenticated, user } = useAuth()

  return (
    <Layout>
      <SEO title="Home" />
      <h1>Hi {isAuthenticated() ? user.name : "people"}</h1>
  )
}

Check isAuthenticated then use the user object. ✌️


For more detailed docs visit useAuth.dev


You can try it out here 👉 https://gatsby-useauth-example.now.sh/

Author

👤 Swizec Teller [email protected]

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

I am looking to support other authentication providers. Please help :)

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2019 Swizec Teller [email protected].
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Dejan

💡

Jason Miller

💻

Graham Barber

💬

Mateus Gabi

📖

Jorge Galat

💻

Swizec Teller

💻 📖 📝 💡 🚧

Nick Richmond

💻

Ollie Monk

📖 💻

Henrik Wenz

🐛

Max Chehab

📖

Joel Bartlett

💻

SIDDIK MEHDI

💻

Jess

🐛

Jorge Cuadra

📖

Øyvind Marthinsen

💻

Fredrik Søgaard

💻

Artem Rudenko

💻

Travers Pinkerton

💻

Eric Hodges

💻

Devin Fitzsimons

📖

Jason Laster

📖 💻 🐛

Patrick Arminio

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

useauth's People

Contributors

aisflat439 avatar allcontributors[bot] avatar dependabot[bot] avatar developit avatar erichodges avatar gvidon avatar jasonlaster avatar jgalat avatar mateusgabi avatar maxchehab avatar murbar avatar nwrichmond avatar omonk avatar oyvinmar avatar patrick91 avatar smehdii avatar swizec avatar traverspinkerton avatar walberty 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  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

useauth's Issues

Potential read obsolete state contextValue

Hi, according to my understanding, useEffect should have all the variables listed in its dependency list, but it seems this line of code https://github.com/Swizec/useAuth/blob/master/src/AuthProvider.js#L53 does not include contextValue in the dependency list.

The current code:

useEffect(() => {
        setContextValue({ ...contextValue, state });
    }, [state]);

Maybe it's better this way?

useEffect(() => {
        setContextValue((contextValue) => {
            return { ...contextValue, state };
        });
    }, [state]);

This allows us not to include contextValue into the dependency list. So we can follow the React Hooks rules.

audience param (auth0_audience_domain)

https://auth0.com/docs/quickstart/backend/nodejs/01-authorization

As far as I understand, when creating a backend to you would take access_token from client, and you would need to verify the token.
One of the key elements to check is audience.

Auth0.com asks to create an API with an identifier (can be anything - doesn't even have to start with https://, right?)
https://auth0.com/docs/getting-started/set-up-api

Identifier: a unique identifier for the API. Auth0 recommends using a URL. Auth0 does differentiate between URLs that include the last forward slash. For example, https://example.com and https://example.com/ are two different identifiers. The URL does not have to be a publicly available URL. Auth0 will not call your API. This value cannot be modified afterwards.

https://github.com/Swizec/useAuth/blob/v0.6.1/src/AuthProvider.tsx#L69

Here, the audience is pre-defined to be /api/v2/ and you are to pass auth0_audience_domain part instead of entire identifier text.

Of course you can overwrite it

https://github.com/Swizec/useAuth/blob/v0.6.1/src/AuthProvider.tsx#L75

like so, but why the provider takes auth0_audience_domain and uses /api/v2/ instead of just an identifier text?

Bro please help me

I am a react native student.. I need a help in axios.. In my project i not get print in android emulator.. I get response in terminal but it not show un emulator..

simplified import paths

Hey Swizec 👋🏽

regarding your workaround over here: https://github.com/Swizec/useAuth/blob/master/auth0.js I just ran into the same problem and looked a bit further for a potential solution. Did you try this one? https://davidwells.io/blog/publishing-flat-npm-packages-for-easier-import-paths-smaller-consumer-bundle-sizes Looks promising and would avoid you having the auth0.js on a top-level. Just wanted to share it, because I noticed your tweet about this topic recently.

Best 🤗

Auth0 redirect from rule not authenticating

After using this system, handleAuthentication does not result in logining the user in, and there is no error thrown

We can confirm that an accessToken has been returned to redirect url specified in the rule, and that the idToken, as well as the accessToken, are valid.

After handleAuthentication the user still not logged in.

Code of the page which the rule redirects to

import React from "react";
import { useRouter } from "next/router";

const Signup = () => {
  const router = useRouter();
  const state = router.query.state;

  console.log(state);

  return (
    <React.Fragment>
      <a href={`https://equivest.us.auth0.com/continue?state=${state}`}>
        Continue !
      </a>
    </React.Fragment>
  );
};
export default Signup;

Code of the rule

function signupNewUser(user, context, callback) {
  if (context.protocol === "redirect-callback" || !user.email) {
    callback(null, user, context);
  }

  function checkUserExists({user_id}, context, done) {
    done(null, false, context);
  }
	
  checkUserExists(user, context, (err, exists, context) => {
    if (err) return callback(err);
    
    context.redirect = {
        url: `http://localhost:3000/signup`
     };
    console.log("User exists and context");
  });
}

Auth0 callback page

import { useEffect } from "react";
import { useAuth } from "react-use-auth";

const Auth0CallbackPage = () => {
  const { handleAuthentication } = useAuth();
  useEffect(() => {
    handleAuthentication();
  }, [handleAuthentication]);

  return (
    <h1>
      This is the auth callback page, you should be redirected immediately!
    </h1>
  );
};
export default Auth0CallbackPage;

Question: TypeScript Typings

I watched the part of the video on you open sourcing this and you mentioned relying on the community to supply typescript typings.

I would be more than happy to help out with this, although there are some different ways we could go about it:

  • Do we re-write react-use-auth in typescript, or just provide the typings as separate *.d.ts files?
    • This is ultimately a @Swizec question as this is your library and you would need to buy in to this. I am personally for it since the library is still rather small and it would not take long to convert to typescript. I have also seen that you have used typescript on some other projects, so it seems that you are familiar with it. The library is also quite limited in scope, meaning it is unlikely to gain a ton of new features over time. The downside however is, it would require all contributors to understand typescript, so it has it's pro/cons.
    • Re-writing it in typescript would mean that the typings are always in sync, and we could get some inferred typings/etc.
    • We could also release a separate @types/react-use-auth npm package and keep the typings completely out of the react-use-auth repository (although these would likely get out of date regularly I'd imagine).
  • Do we use tsc for the builds or babel and @babel/plugin-transform-typescript?
    • Using babel allows us to leverage other babel plugins like macros, etc (although none are currently used)
    • babel does not support all typescript features, but 98% of them

Access to user_metadata

This may be more of a question, but I am hoping to access the meta data of the user by overriding the auth0_params and wondering if this is how to get access to meta data through the useAuth config


    <AuthProvider
        navigate={navigate}
        auth0_domain="xxxxx"
        auth0_client_id="xxxxx"
        auth0_params={{ scope: "openid profile email user_metadata"}}
    >
        {element}
    </AuthProvider>

How supportive is this library of using it without auth0

Hey,

I have custom auth via rails. Do you think this integration will work? This is not a bug but more of an enhancement questions. If this library can be used independently without auth0.

I do see that I can just provide any endpoints I wish in the config but not sure if someone already tried that and there are some specifics that are only going to work if auth0 is used.

useSession returns undefined | token

lets say am using JWT credentials....i need to get the token from the useSession hook.

export const useAxiosPrivate = () => {

    const { data, status } = useSession()
    console.log(data)

    const axiosInstance = axios.create({
        baseURL: `${SERVER_LOCALHOST}/api/v1`,
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${data?.user.accessToken}`
        }
    })

    return axiosInstance


}

i feel like because it will always return null | token,some requests will be sent with Bearer undefined....it there a way to avoid this???

Next.js build cannot resolve 'react-use-auth/auth0'

I went through these steps this morning and ran into a build issue.

  1. npx create-next-app
  2. yarn add react-use-auth auth0-js
  3. update pages/_app.js from https://useauth.dev/docs/auth0/
  4. yarn build
  5. yarn dev

Build Error

here's what i see when i run yarn dev

➜  next-auth git:(main) yarn dev
yarn run v1.22.4
$ next dev
ready - started server on http://localhost:3000
error - ./node_modules/react-use-auth/dist/react-use-auth.esm.js:1:4504
Module not found: Can't resolve 'react-use-auth/auth0'

node_modules files

Here are the files I see in react-use-auth

node_modules/react-use-auth
├── LICENSE
├── README.md
├── dist
│   ├── AuthConfig.d.ts
│   ├── AuthProvider.d.ts
│   ├── NetlifyIdentity.esm.js
│   ├── NetlifyIdentity.esm.js.map
│   ├── NetlifyIdentity.js
│   ├── NetlifyIdentity.js.map
│   ├── NetlifyIdentity.modern.js
│   ├── NetlifyIdentity.modern.js.map
│   ├── NetlifyIdentity.umd.js
│   ├── NetlifyIdentity.umd.js.map
│   ├── __tests__
│   │   ├── AuthConfig.spec.d.ts
│   │   ├── AuthProvider.spec.d.ts
│   │   ├── authReducer.spec.d.ts
│   │   └── useAuth.spec.d.ts
│   ├── auth0.esm.js
│   ├── auth0.esm.js.map
│   ├── auth0.js
│   ├── auth0.js.map
│   ├── auth0.modern.js
│   ├── auth0.modern.js.map
│   ├── auth0.umd.js
│   ├── auth0.umd.js.map
│   ├── authReducer.d.ts
│   ├── index.d.ts
│   ├── index.js
│   ├── index.js.map
│   ├── index.modern.js
│   ├── index.modern.js.map
│   ├── index.module.js
│   ├── index.module.js.map
│   ├── index.umd.js
│   ├── index.umd.js.map
│   ├── providers
│   │   ├── NetlifyIdentity.d.ts
│   │   ├── auth0.d.ts
│   │   └── index.d.ts
│   ├── react-use-auth.esm.js
│   ├── react-use-auth.esm.js.map
│   ├── react-use-auth.js
│   ├── react-use-auth.js.map
│   ├── react-use-auth.modern.js
│   ├── react-use-auth.modern.js.map
│   ├── react-use-auth.umd.js
│   ├── react-use-auth.umd.js.map
│   ├── types.d.ts
│   └── useAuth.d.ts
├── package.json
└── src
    ├── AuthConfig.tsx
    ├── AuthProvider.tsx
    ├── __tests__
    │   ├── AuthConfig.spec.tsx
    │   ├── AuthProvider.spec.tsx
    │   ├── authReducer.spec.ts
    │   └── useAuth.spec.tsx
    ├── authReducer.ts
    ├── index.ts
    ├── providers
    │   ├── NetlifyIdentity.ts
    │   ├── auth0.ts
    │   └── index.ts
    ├── types.ts
    └── useAuth.ts

Reloading loses session in Chrome v80

Hi,

After spending a long time debugging my app using useAuth I realised that this issue was happening in Chrome (and in incognito mode so it doesn't appear to be any plugins), but not FF (neither in private window mode).

So I tried the example app:

https://gatsby-useauth-example.now.sh/

It works and retains the session in Safari v13.1 (14609.1.20.111.8) but session is lost in Chrome v80.0.3987.163 (and in FF v68.5.0esr) upon reloading after logging in.

I'm on (OSX Mojave 10.14.6)

Re-render issues

Please note that the following code will cause a re-render of your entire subtree.

value={{
state,
dispatch,
auth0,
callback_domain,
navigate
}}

Because context uses reference identity to determine when to re-render, there are some gotchas that could trigger unintentional renders in consumers when a provider’s parent re-renders.

https://reactjs.org/docs/context.html#caveats

Possible solutions to this problem

  1. Use a class component and lift your context into this.state
  2. Use React.useMemo()

Access token of logged in user

I'm using Auth0 to allow users to login via GitHub.

I now need to get at the OAuth token from GitHub so I can make authorised requests to the GitHub API. I think maybe useAuth could expose this token too, if it can? (I'm not super familiar with auth0 so sorry if I'm heading down the wrong path here).

This library made auth so much easier so thank you for that!

trying to use useAuth with apollo client and nextjs

thanks for this work!

I'm trying to integrate useAuth with ApolloClient and nextjs.
I started from the code provided in the nextjs example, and now I'm adding Apollo. The client needs the access token so I'm did something like this:

export default function App({ Component, pageProps }) {
  const router = useRouter();
  return (
    <AuthProvider
      navigate={router.push}
      auth0_domain="..."
      auth0_client_id="..."
    >
      <ApolloWrapper>
        <Component {...pageProps} />
      </ApolloWrapper>
    </AuthProvider>
  );
}

// eslint-disable-next-line react/prop-types
function ApolloWrapper({ children }) {
  const { authResult, isAuthenticating, isAuthenticated } = useAuth();
  console.log({
    authResult,
    isAuthenticating,
    isAuthenticated: isAuthenticated(),
  });
  const client = createApolloClient(authResult && authResult.idToken);
  return <ApolloProvider client={client}>{children}</ApolloProvider>;
}

it works as long I'm staying in the app.
for some reason when I refresh the page (I disabled ublock), authResult becomes null and I can't send any request to the db (fails because missing access token)

README.md Guidance on Use Case: Save User To Server After Registration

I was wondering if @Swizec, or anyone could offer any guidance as to how to persist a newly registered user on my server after "signup" via Auth0?

Before integrating useAuth, I had a login form that would collect, name, email, password, aboutMe, etc, then, hit my GraphQL server, create a user entry in my User table, and return a JWT for use in subsequent requests for editing properties in the user's model.

I'm not seeing a clear path forward on doing something similar with useAuth. Is this not a good use case for useAuth?

I think this would be a great addition to the examples folder if it is possible.

App logs out from google-oauth2 connection a second after the page refresh

This is a little weird, my gatsby app for some reason logs out a few seconds after refresh. A normal username-password-authentication connection works fine. The following is the state a second after the refresh:

authResult: null,
error: {
  code: "login_required", 
  description: "Login required"
  error: "login_required"
  error_description: "Login required",
  original: {
    error: "login_required", 
    error_description: "Login required
  }
},
errorType: "checkSession",
expiresAt: null,
isAuthenticating: false,
user: {}

auth0_callback

import React, { useEffect } from "react"
import { useAuth } from "react-use-auth"
import Layout from "../components/layout"

const AuthCallback = () => {
  const { handleAuthentication } = useAuth()
  useEffect(() => {
    handleAuthentication({ postLoginRoute: "/" })
  }, [])
  return <Layout>Redirecting to home...</Layout>
}

export default AuthCallback

Secured routes?

Is there any plan to add ability to secure a route? i.e. require logged in to access /account?

Regular js react app asking for typescript declarations

Bear with me as I just got started with React.
Installed module through yarn

yarn add react-use-auth

Immediately when I slap

import { useAuth } from "react-use-auth";

in my index.js file I get a little warning on that line stating:

Could not find a declaration file for module 'react-use-auth'. '/Users/<omitted>/SERVER/with-apollo/with-apollo-npm/node_modules/react-use-auth/dist/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-use-auth` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-use-auth';`ts(7016)

Unsure why it is asking for typescript declarations - I thought I was doing everything in plain JS.
I thought that this was just a warning and this would not affect the functioning of the module but, while running the actual app I got a warning stating:

TypeError: Cannot read property 'state' of null

At this line:

  const { isAuthenticated, login, logout, isAuthenticating, user } = useAuth()

What I did to make sure that it becomes more plausible that the typescript warning above is causing this is the following 'reverse engineering' procedure I followed:

I copied all the files from this module into my 'local' filesystem (lib folder) and called them this way - in stead of via the node_modules dir.

Result: The typescript error went away and I no longer have the Cannot read property 'state' of null error anymore.
What's better : the login procedure works. I can log in and log out.

Does this support Firebase Auth?

Hello, I think I heard you say this hook supports Firebase Authentication too in yesterday's stream. Can you point me towards a resource or documentation about using Firebase Auth with this?

If successful, I would love to send an example as a PR

useauth.dev is not logging in

It looks like the example is not working because the authConfig is not provided.

Here is a replay of my last session.

See the comment about the provider not being present and the wrapPageElement not being called in src/index...

I'm looking into why, but still new here :)

Losing user

Very momentarily our User comes through

Screen Shot 2020-05-09 at 1 08 31 PM

Followed by

Screen Shot 2020-05-09 at 1 08 17 PM

Console

Screen Shot 2020-05-09 at 1 09 52 PM

Gatsby Build Error: WebAuth is not a constructor

Everything runs as expected on gatsby develop, but as soon as I try and run gatsby buildI get a Webpack error:

WebpackError: TypeError: auth0_js__WEBPACK_IMPORTED_MODULE_1___default.a.WebAuth is not a constructor
  
  - index.module.js:1 f
    node_modules/react-use-auth/dist/index.module.js:1:2878

The only suggestion I've found online is to try running gatsby clean and reinstalling node packages before trying again, but I haven't had any luck. Would anyone have an idea what might be causing this?

vanilla example?

any chance youd have a simple example without the gatsby stuff?

What is the correct way to setup a development repo in localhost?

What is the correct way to setup development repo?

Here is what I did:

  1. Created a Next JS project and made it run using react-use-auth library.
  2. Cloned this git repo.
  3. Yarn Link the repo & react-use-auth
  4. Yarn dev

This gives me following error (screenshot is attached).

Please help with the correct way to contribute to the project.

Screenshot from 2020-12-30 20-03-11

Non authenticated page flashes after login and callback page

Hello, I am using this package and after loggin in with Auth0, my callback page flashes, and then before I see the authenticated content, the non-authenticated content flashes on the screen.

After seeing the callback, I would not expect to see the non-authenticated content flash on the screen.

Is there a way to prevent this?

NextJS build fails on Vercel

I have a minimal NextJS app configured with useAuth and Auth0 as provider.

The build fails when running on Vercel.

Not sure if I am doing things wrong, but the build completes successfully when running it locally using next build.

import { AuthConfig, Providers } from "react-use-auth";
import Head from 'next/head'
import { useRouter } from "next/router";

import '../styles/globals.css'
import Layout from './_layout/Layout'

function MyApp({ Component, pageProps }) {
  const router = useRouter();

  return (
    <>
      <Head>
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <AuthConfig
          authProvider={Providers.Auth0}
          navigate={(url) => router.push(url)}
          params={{
              domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN,
              clientID: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID
          }}
      />
      <Layout>
        <Component {...pageProps} />
      </Layout>
    </>
  )
}

export default MyApp

Error


09:18:04.383 | Failed to compile.
-- | --
09:18:04.383 | ModuleNotFoundError: Module not found: Error: Can't resolve 'netlify-identity-widget' in '/vercel/workpath0/node_modules/react-use-auth/dist'
09:18:04.383 | > Build error occurred
09:18:04.384 | Error: > Build failed because of webpack errors
09:18:04.384 | at build (/vercel/workpath0/node_modules/next/dist/build/index.js:15:918)
09:18:04.384 | at runMicrotasks (<anonymous>)
09:18:04.384 | at processTicksAndRejections (internal/process/task_queues.js:97:5)
09:18:04.414 | Error: Command "next build --debug" exited with 1

Full build log

09:14:02.075  	Cloning github.com/martinnormark/mortimer-nextjs (Branch: master, Commit: d94e474)
09:14:03.276  	Cloning completed in 1201ms
09:14:03.279  	Analyzing source code...
09:14:04.021  	Installing build runtime...
09:14:04.473  	Build runtime installed: 451.812ms
09:14:05.387  	Installing dependencies...
09:14:05.840  	npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
09:14:16.176  	> [email protected] install /vercel/workpath0/node_modules/sharp
09:14:16.176  	> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
09:14:16.330  	info sharp Using cached /vercel/.npm/_libvips/libvips-8.10.0-linux-x64.tar.br
09:14:17.364  	> @ampproject/[email protected] postinstall /vercel/workpath0/node_modules/@ampproject/toolbox-optimizer
09:14:17.364  	> node lib/warmup.js
09:14:17.868  	�[7mAMP OPTIMIZER�[0m Downloaded latest AMP runtime data.
09:14:18.305  	npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/watchpack-chokidar2/node_modules/fsevents):
09:14:18.305  	npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
09:14:18.312  	npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
09:14:18.313  	npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
09:14:18.315  	added 872 packages from 477 contributors in 12.504s
09:14:18.654  	50 packages are looking for funding
09:14:18.654  	  run `npm fund` for details
09:14:18.684  	Running "npm run build"
09:14:18.878  	> [email protected] build /vercel/workpath0
09:14:18.878  	> next build
09:14:19.544  	info  - Creating an optimized production build...
09:14:19.560  	Attention: Next.js now collects completely anonymous telemetry regarding usage.
09:14:19.560  	This information is used to shape Next.js' roadmap and prioritize features.
09:14:19.560  	You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
09:14:19.560  	https://nextjs.org/telemetry
09:14:25.091  	Failed to compile.
09:14:25.091  	ModuleNotFoundError: Module not found: Error: Can't resolve 'netlify-identity-widget' in '/vercel/workpath0/node_modules/react-use-auth/dist'
09:14:25.091  	> Build error occurred
09:14:25.092  	Error: > Build failed because of webpack errors
09:14:25.092  	    at build (/vercel/workpath0/node_modules/next/dist/build/index.js:15:918)
09:14:25.092  	    at runMicrotasks (<anonymous>)
09:14:25.092  	    at processTicksAndRejections (internal/process/task_queues.js:97:5)
09:14:25.124  	npm ERR! code ELIFECYCLE
09:14:25.124  	npm ERR! errno 1
09:14:25.129  	npm ERR! [email protected] build: `next build`
09:14:25.129  	npm ERR! Exit status 1
09:14:25.129  	npm ERR! 
09:14:25.129  	npm ERR! Failed at the [email protected] build script.
09:14:25.129  	npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
09:14:25.137  	npm ERR! A complete log of this run can be found in:
09:14:25.137  	npm ERR!     /vercel/.npm/_logs/2020-12-11T08_14_25_130Z-debug.log
09:14:25.141  	Error: Command "npm run build" exited with 1
09:14:27.289  	Done with "package.json"

Request for help: Kickass site for useAuth.dev

👋

useAuth is doing great as an opensource project, we're at 1.1k stars 😍
So I recently bought useAuth.dev and put the gatsby example page up. This is an okay start, but we need something better.

Unfortunately I don't have bandwidth to make the site myself. And I suck as a designer too.

Therefore I want to open this up as a request for help for webdev newbies who want to flex their skills. You can use this as a learning opportunity for Gatsby (or maybe Next?), React, design, frontend, whatever you like. Use it in your portfolio, to land paying gigs (I might have some in the pipeline), have a project to show at interviews, etc. Up to you :)

First, I'm thinking of this as a volunteer/opensource/forexperience/exposure project. useAuth itself is pure opensource without a business model and I want to keep it that way. That's why I'm looking for newbies to do this as a learning opportunity :)

If that works for you 👇

  1. I'd be excited if something happens by mid December
  2. Going live in january would be kickass
  3. I can help with guidance and reviewing PRs, I don't have bandwidth to get hands-on involved
  4. If you start by sketching some designs, that would be wonderful
  5. The site needs to do these jobs:
  • explain why useAuth exists
  • explain who it's for
  • explain what it does
  • provide documentation on how to use it
  • link to live examples
  • preferably be a live example itself
  • needs to link to GitHub and explain useAuth is opensource
  • the site itself needs to be opensource
  • site should work on mobile and web
  • needs to be easily hostable on Zeit (because I bought the domain there and I'm too lazy to move)
    5.1 I can write copy for all of this
  1. Anything else is not important as long as the site passes the "looks cool" test and doesn't get in the way of doing its jobs from 5
  2. I really like https://rebassjs.org/, https://www.gatsbyjs.org/, https://preactjs.com/, and https://nextjs.org/ as inspiration
  3. you are the ideal user for this site. Anyone who wants to add authentication to their React app and doesn't know how

Interested? Leave a comment, ask questions, ping me on twitter, or just get started. :)

Persist login status on refresh

Love this module, so easy to integrate and work with, just wondering one thing:

From what I can tell this should persist the user being logged in between refreshes or am I being slow? It's logging out user between refreshes, localStorage values still present...

Clarify user info storage in README

I thought there was some confusing wording in the readme about using cookies and localstorage.

cookie in local storage with your user's information

https://github.com/Swizec/useAuth/blame/master/README.md#L126

  1. I didn't think it was possible to store a "cookie in localstorage". You either store info in a cookie or store info in local storage but not a cookie in local storage.

  2. It says "user information". If this is non-secret stuff from the ID token like name I suppose that's ok but as I understood Auth0 was following all the best practices and not storage sensitive / secrete info in localStorage since it could be compromised by 3rd party scripts. Maybe clarify what this user information is so users don't get worried and think this library is risky.

Publish sourcemaps

It looks like sourcemaps are created, but not published, which makes it difficult to understand what the library is doing.

Does it support react native?

useAuth works pretty great for web, but what about React Native or Ionic? Is there any plan to add the support? 😁

SyntaxError: Unexpected token 'export'

When I run next-js project with simple setup, I get this error.

error - /home/chinmay/Projects/next-useauth-starter/node_modules/react-use-auth/auth0.js:4
export { Auth0 } from "./dist/auth0";
^^^^^^

SyntaxError: Unexpected token 'export'

My code:
__app.js

return (
    <>
      <AuthConfig
        navigate={(url) => router.push(url)}
        authProvider={Auth0}
        params={{
          domain: "useauth.auth0.com",
          clientID: "GjWNFNOHqlino7lQNjBwEywalaYtbIzh",
        }}
      />

      <Component {...pageProps} />
    </>
  );

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.