nookies | 🍪 A set of cookie helpers for Next.js | Frontend Framework library
kandi X-RAY | nookies Summary
kandi X-RAY | nookies Summary
A collection of cookie helpers for Next.js.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of nookies
nookies Key Features
nookies Examples and Code Snippets
Community Discussions
Trending Discussions on nookies
QUESTION
I am using firebase auth with TS in a nextJS app.
I am trying to setup AuthProvider and use context.
...ANSWER
Answered 2022-Apr-08 at 19:26You need to return a Promise
from login method but you just have the type written atm. Try refactoring the code to:
QUESTION
I have a Firestore collection by the name of "mentor". Each document in the collection contains three fields: "name", "email" and "linkedin".
I want to fetch all the documents in the collection and pass them as props. I want to then access these document fields to be rendered on my page.
I am using getServerSideProps to fetch the Firestore data prior to rendering the page. My code is as follows:
dashboard.js:
...ANSWER
Answered 2022-Feb-06 at 19:42doc.data
is a function, not actual document data. See the API documentation for clarity. You should instead call it in order to get an object with the data in the snapshot.
QUESTION
So, here's the situation.
I'm trying to get a "language" cookie in the app initialization to change the UI accordingly. For example, if the language is "Arabic" (ar), I revert the layout to be "RTL", and vise versa.
There are two ways to achieve this, the first solution is to get the cookie inside "useEffect()", like this ...
...ANSWER
Answered 2022-Jan-08 at 12:36I'm not sure if this helps, but there might be a way to avoid the flicker. Instead of defaulting to English / LTR, Next.js actually has configurable i18n routing, which tries to detect the user's preferred locale using browser headers. There's even cookie support, but it has to be the hardcoded NEXT_LOCALE
cookie.
Even if you've already explored that solution, I'll just leave it here for anyone else with a similar problem.
============= SOLUTION USING NEXT.JS i18n routing ===========
Thanks to @Summer advice I was able to solve my issue using Next.js built-in i18n routing solution that I was not aware it exists.
The issue that caused the UI flicker was happening because I was waiting until the useEffect()
function gets executed in _app.tsx in order to add some kind of a special CSS class or HTML attribute the tag in order to be able to target that CSS class in the CSS file and switch the direction or do any other CSS modifications.
But now by using the built-in Next.js i18n routing, Next.js detect the language of your app, either by looking for a "NEXT_LOCALE" cookie or if he can't find that he will default to the default language of your choice, and by doing that Next.js will add a "lang" attribute automatically to your tag that comes directly from the server, and then you can target that in your CSS to switch your layout direction ...
QUESTION
There are numerous questions relating to useEffect() and running on initial page render. I am experiencing the same problem even after making sure my code is correct regarding parameters passed to useEffect.
...ANSWER
Answered 2021-Nov-30 at 14:14It's not clear for me this problema, but I try to write what I see: you have defined useEddect with the fetch without deps. In that fetch you use role state which is initialized to empty string in the first time. You set the role using setRole in the same useEffect but this has no effect for the precedent reasons.
My suggestion is to remove role state and redefine useEffect like this:
QUESTION
I am using Firebase for auth in my project. After user authenticates, I set his/her id token in cookies, so that next time any request is made to auth-only page, I can verify the token server-side for SSR.
However, the wrapper function I wrote for this errors out as 'ReferenceError' when used in getServerSideProps
.
lib/firebase-admin.ts
...ANSWER
Answered 2021-Nov-01 at 03:08I fixed the problem! (thanks @ArneHugo the hint)
So, what happened was not really a cyclic dependency, but files getting compiled asynchronously, because of which there was no actual control over what got compiled first.
I fixed this by making a small change:
lib/firebase-admin.ts
QUESTION
I am using firebase for authentication in my Next.js app and also I have an express server that serves a REST API, which has a middleware that uses firebase-admin
to verify idToken
that is sent from my app, to pass the authenticated routes
Currently
The idToken generated by firebase lasts for one hour and if the client is still on my app and
hits any route that needs idToken
and if the idToken
is expired then the server just throws an error as unauthenticated, which is pretty good work, but this is not desired, I know my user is in there and just idToken
is expired
Question
How do I refresh my idToken
of a user if it has expired, without having to do a full refresh in the browser to get new idToken
Some Code
...ANSWER
Answered 2021-Sep-06 at 07:38The Firebase SDK does that for you. Whenever you call user.getIdToken()
it will return a valid token for sure. If the existing token has expired, it will refresh and return a new token.
You can use onIdTokenChanged()
and which will trigger whenever a token is refreshed and store it in your state.
However, I don't see any cons in using getIdToken()
method whenever you are making an API request to server. You won't have to deal with IdToken observer and get valid token always.
QUESTION
Following a few tutorials like this one, I was able to deploy my Next.js
app to Firebase Hosting/Functions. Here's the reduced folder structure of my project:
ANSWER
Answered 2021-Aug-06 at 17:24While you could lift the /functions
directory to your project's root directory, this would mean that your other functions are unnecessarily bloated with all of your Next.js
app's dependencies.
When you deploy a Cloud Function, everything in the configured deployment directory (/functions
by default) is deployed - even if you don't use it. It is also deployed once for each function. So if you had a 10MB file to your functions directory, every function's deployed size would increase by 10MB. This is what I mean by "bloating" a function.
FYI: You can change the deployed functions directory by adding the following to your firebase.json
file (docs):
QUESTION
My nodemon keeps getting stuck at restarting due to changes. I am currently using Next.js framework. I have tried installing and uninstalling nodemon but it doesn't work.
Following is my package.json
...ANSWER
Answered 2021-Aug-02 at 03:39This is how I solved this nodemon issue in next js.
a. I downloaded nodemon in dev dependency of 2.0.7 . Seems like the newer versions are causing problems in my local.
b. Update the scripts in package.json
QUESTION
I've got several pages that I want to call a query inside of getServerSideProps
to request the currentUser.
What I have currently is something like this:
...ANSWER
Answered 2021-Jun-21 at 14:20Thanks to @juliomalves in the comments, I simply forgot to return the withAuth
function!
Here's how it looks now:
pages/index.tsx
QUESTION
I'm trying to refresh the users auth token on the server in NextJS, currently I have the token set in cookies that I access like this:
...ANSWER
Answered 2021-Jun-20 at 16:23I had similar issue using NuxtJS and the easiest way is to redirect user to a different page where you can get a new Firebase ID Token on client side and then refresh the cookie. For example, you may redirect to a page something like https://domain.tld/auth/refresh?redirect_uri=/dashboard
. The query parameter redirect_uri tells where the user was and must be redirected back after refreshing the token.
If you want to avoid the redirect, you would have to store the "Refresh Token" on your server side. I am not sure how secure that will be but don't store refresh token in cookies. But just in case you are wondering how to get new Firebase ID Token using the refresh token, you can make a POST request to this URL:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nookies
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page