I'm trying to build a Nuxt SSR application using #nuxtjs/firebase and #nuxtjs/pwa
My authentication works as expected when online but when when the user is offline I get this error in console
asyncToGenerator.js:8 Uncaught (in promise) t {code: "auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred.", a: null}
Here's the screenshot of the error message:
This error freezes my app (my navigation hamburger menu doesn't respond)
PWA config in nuxt.config.js:
pwa: {
manifest: {
lang: 'en',
background_color: '#000000',
},
meta: {
nativeUI: true,
appleStatusBarStyle: 'black',
theme_color: '#000000',
},
config: {
enabled: true
},
workbox: {
importScripts: [
'/firebase-auth-sw.js'
],
dev: process.env.NODE_ENV === 'development',
}
}
Here is my Firebase config in nuxt.config.js
firebase: {
config: {
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
databaseURL: process.env.databaseURL,
projectId: process.env.projectId,
storageBucket: process.env.storageBucket,
messagingSenderId: process.env.messagingSenderId,
appId: process.env.appId,
measurementId: process.env.measurementId
},
services: {
auth: {
ssr: true,
initialize: {
// use authData from action in custom mutation
// onAuthStateChangedMutation: 'ON_AUTH_STATE_CHANGED_MUTATION',
onAuthStateChangedAction: 'onAuthStateChangedAction'
}
}
}
}
My onAuthStateChangedAction in store/index.js:
async onAuthStateChangedAction({ dispatch, commit }, { authUser }) {
if(!authUser) return commit(MUTATION_TYPE.REMOVE_USER)
// if user is already authenticated
// get authenticated user profile from firestore
dispatch('getUser', authUser)
if(process.browser) commit(MUTATION_TYPE.SET_TOKEN, localStorage.token)
}
Related
I reviewed everything, my client ID/Secret and everything is fine in my environment variables, when I click to sign in with google in localhost it works perfectly but in vercel it throws this error
[GET] /api/auth/error?error=OAuthSignin
Here is my [...nextauth].js code
import NextAuth from "next-auth/next";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
import { MongoDBAdapter } from "#next-auth/mongodb-adapter";
import clientPromise from "../../../lib/mongodb";
export default NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
authorization: {
params: {
redirect_uri: "https://theracakecairo.com/api/auth/callback/google",
prompt: "consent",
scope: "email",
},
},
}),
FacebookProvider({
clientId: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
authorization: {
params: {
redirect_uri: "https://theracakecairo.com/api/auth/callback/facebook",
prompt: "consent",
// access_type: "offline",
scope: "email",
response_type: "code",
},
},
}),
],
debug: true,
secret: process.env.NEXTAUTH_SECRET,
adapter: MongoDBAdapter(clientPromise),
callbacks: {
async session({ session, token, user }) {
session.user._id = user.id;
return session;
},
},
// session: {
// strategy: "database",
// maxAge: 30 * 24 * 60 * 60
// }
});
https://next-auth.js.org/errors
Walked through the 3 possible error causes and still nothing works
Update:
This issue has been corrected by the Vercel team. Please redeploy your application.
https://github.com/nextauthjs/next-auth/issues/6688#issuecomment-1426614069
The issue is being discussed on GitHub:
https://github.com/nextauthjs/next-auth/issues/6688
https://github.com/nextauthjs/next-auth/issues/6685
Some users say that migrating to Netlify has solved their issues.
https://github.com/nextauthjs/next-auth/issues/6685#issuecomment-1426535665
I'm making a website by using next.js.
After deploying my project by Vercel, login api gives me 502 error.
const nextConfig = {
reactStrictMode: true,
images: {
domains: [process.env.ORIGINAL_DATA, process.env.CONVERT_DATA]
},
swcMinify: true,
env: {
ORIGINAL_DATA : `https://${process.env.ORIGINAL_DATA}`,
CONVERT_DATA : `https://${process.env.CONVERT_DATA}`,
},
async rewrites() {
return [
{
source: "/api/:path*",
destination: `http://${process.env.API}api/:path*`,
},
{
source: "/video/:filename*",
destination: `https://${process.env.CONVERT_DATA}:filename*`,
}
]
},
}
My config codes are here.
In development mode, it does work.
Does anyone know why this is happening??
is there something wrong in rewrites fnc??
I double checked env variables...
I've cleaned cache and cookies...
I am using RTK-Query, and Redux-toolkit for this app, and I created an api-slice with createApi, as per the docs.
When I run a request to the backend, I get a "FETCH_ERROR"; however, when I run the same request using Axios, I get the data correctly from the backend, which leads me to believe I have an error in my code. I am just not sure where exactly it is.
Here is the error:
Object {
"api": Object {
"config": Object {
"focused": true,
"keepUnusedDataFor": 60,
"middlewareRegistered": true,
"online": true,
"reducerPath": "api",
"refetchOnFocus": false,
"refetchOnMountOrArgChange": false,
"refetchOnReconnect": false,
},
"mutations": Object {},
"provided": Object {},
"queries": Object {
"test(undefined)": Object {
"endpointName": "test",
"error": Object {
"error": "TypeError: Network request failed",
"status": "FETCH_ERROR",
},
"requestId": "BWOuLpOxoDKTzlUYFLW4x",
"startedTimeStamp": 1643667104869,
"status": "rejected",
},
},
"subscriptions": Object {
"test(undefined)": Object {
"QJSCV641RznGWyudGWuMb": Object {
"pollingInterval": 0,
"refetchOnFocus": undefined,
"refetchOnReconnect": undefined,
},
},
},
},
"test": Object {
"data": Array [],
},
}
Here is the test slice:
import { createSlice } from "#reduxjs/toolkit";
const testSlice = createSlice({
name: "test",
initialState: {
data: [],
},
reducers: {
getData: (state) => {
state;
},
},
});
export const { getData } = testSlice.actions;
export default testSlice.reducer;
Here is the apiSlice:
import { createApi, fetchBaseQuery } from "#reduxjs/toolkit/query/react";
export const apiSice = createApi({
reducerPath: "test",
baseQuery: fetchBaseQuery({ baseUrl: process.env.REACT_APP_backend_url }),
endpoints: (builder) => ({
test: builder.query({
query: () => "/test",
}),
}),
});
export const { useTestQuery } = apiSice;
I solved it by changing the backend URL to my current ipv4 (for expo development, otherwise just your whatever your backend URL is) address in my .env file, then deleting cache, and restarting my app. In my case I was using expo so, expo r -c, and it worked.
i did : npm install #nuxtjs/onesignal
modules: [
'#nuxtjs/axios',
'#nuxtjs/onesignal',
'#nuxtjs/pwa',
],
oneSignal: {
init: {
appId: '19023887-4044-4db8-90ec-9c5ff515xxx',
allowLocalhostAsSecureOrigin: true,
welcomeNotification: {
disable: false
}
}
},
issue 1:
it keeps reloading my page ....
issue 2:
no notification is coming..
issue 3: _this.$OneSignal.isPushNotificationsEnabled is not a function
I am getting following exception, while calling signInWithEmailAndPassword method of firebase:
Following is the code of my content.js file:
var config = {
apiKey: "******",
authDomain: "******",
databaseURL: "******",
projectId: "******",
storageBucket: "******",
messagingSenderId: "******"
};
var firebase_email = "firebase_email"; var firebase_password = "firebase_password";
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword(firebase_email, firebase_password)
.then((result) => console.log('Signin result', result))
.catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === "auth/wrong-password") {
alert("Wrong password for Firebase API in config.");
} else {
console.log(errorMessage);
}
console.log(error);
});
And following is the code of my manifest.json file:
{
"manifest_version": 2,
"name": "Firebase Auth in Chrome Extension Sample",
"description": "This sample shows how to authorize Firebase in a Chrome extension using a Google account.",
"version": "0.1",
"content_scripts": [{
"matches": [
"https://some websitename*",
],
"js": ["jquery-3.2.1.min.js", "firebase.js", "content.js"]
}],
"browser_action": {
"default_icon": "icon.png",
"default_title": "My Extension!"
},
"permissions": [
"identity",
"https://*/*",
"activeTab",
"background",
"storage"
],
"content_security_policy":"script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'"
}
Strange, the same code works when I run it as JavaScript Application, see the below screenshot:
I tried various things, but could not identify the reason behind this.
Please guide me in right direction.
Thanks