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

localStorage is not defined - with SSR (NextJS) #802

Open
stolinski opened this issue Sep 10, 2019 · 4 comments
Open

localStorage is not defined - with SSR (NextJS) #802

stolinski opened this issue Sep 10, 2019 · 4 comments

Comments

@stolinski
Copy link
Contributor

Trying to use with NextJS and I'm getting "localStorage is not defined". Should be an easy enough fix. I can try and submit a PR if you would like

ReferenceError: localStorage is not defined
    at Object.<anonymous> (/Users/scotttolinski/Sites/levelup/node_modules/apollo-accounts-password-client/node_modules/@accounts/client/lib/token-storage-local.js:49:39)
@agustif
Copy link
Contributor

agustif commented Sep 11, 2019

@stolinski Please do!! I'm currently looking to do the same thing, would really appreciate your PR! I'm sure @pradel will be happy to review and merge it too! Could make a nice example, and be on the docs/homepage.

I think it should be fairly easy to pass a different storage like in the cookbook for react-native:

import AsyncStorage from '@react-native-community/async-storage'; import { AccountsClient } from '@accounts/client'; const accounts = new AccountsClient({ // We tell the accounts-js client to use AsyncStorage to store the tokens tokenStorage: AsyncStorage, });

but with the proper cookieStorage

edit: Something like mixing these: https://github.com/zeit/next.js/tree/canary/examples/with-cookie-auth
https://accounts-js.netlify.com/docs/cookbook/react-native

@stolinski
Copy link
Contributor Author

The solution would be to just check to see if localStorage exists before calling it. Unfortunately, I haven't had the time to dive in yet as I was unable to get started with the repos locally following the getting started docs. I need to find some time to dedicate to figuring that out.

@agustif
Copy link
Contributor

agustif commented Oct 2, 2019

The solution would be to just check to see if localStorage exists before calling it.

I think @pradel already fixed this on my PR

Unfortunately, I haven't had the time to dive in yet as I was unable to get started with the repos locally following the getting started docs. I need to find some time to dedicate to figuring that out.

I’m on a cruiseship in a transatlantic trip, so my wifi sux big time! But please tell me how can I help you @stolinski. I’ve had to use npm install and not yarn in some of the packages for them to work in my local machine. And also use yarn link to use some local packages like @accounts/client to test the nextJS example with the cookie storage ;)

@edw19
Copy link

edw19 commented Jan 13, 2021

There are someone example the accountsjs con nextjs ? if exists could you help me

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

3 participants