Skip to content

Instantly share code, notes, and snippets.

@vpaladino778
Created December 22, 2021 17:12
Show Gist options
  • Save vpaladino778/1020d0cb633d16cb5884ec50b7dc2697 to your computer and use it in GitHub Desktop.
Save vpaladino778/1020d0cb633d16cb5884ec50b7dc2697 to your computer and use it in GitHub Desktop.
// ./initAuth.js
import { init } from 'next-firebase-auth';
const initAuth = () => {
init({
debug: true,
authPageURL: '/login',
appPageURL: "/dashboard",
loginAPIEndpoint: '/api/login', // required
logoutAPIEndpoint: '/api/logout', // required
firebaseAuthEmulatorHost: process.env.FIREBASE_AUTH_EMULATOR_HOST,
// Required in most cases.
firebaseAdminInitConfig: {
credential: {
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
// The private key must not be accessible on the client side.
privateKey: process.env.FIREBASE_PRIVATE_KEY ? JSON.parse(process.env.FIREBASE_PRIVATE_KEY) : undefined,
},
databaseURL: 'https://my-example-app.firebaseio.com',
},
// Use application default credentials (takes precedence over fireaseAdminInitConfig if set)
// useFirebaseAdminDefaultCredential: true,
firebaseClientInitConfig: {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY ?? "",
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: "sweep-----.appspot.com", // Obfuscated this
messagingSenderId: "70273081587",
appId: "1:70273081587:web:2c868e0da3160be1375786",
measurementId: "G-LNGM5LTMDD"
},
cookies: {
name: 'Sweep', // required
// Keys are required unless you set `signed` to `false`.
// The keys cannot be accessible on the client side.
keys: [process.env.COOKIE_SECRET_CURRENT, process.env.COOKIE_SECRET_PREVIOUS],
httpOnly: true,
maxAge: 12 * 60 * 60 * 24 * 1000, // twelve days
overwrite: true,
path: '/',
sameSite: 'strict',
secure: false, // set this to false in local (non-HTTPS) development
signed: true,
},
/**
* Optional function: handler called if there's an unexpected error while
* verifying the user's ID token server-side.
*/
// onVerifyTokenError: (err) => {}
/**
* Optional function: handler called if there's an unexpected error while
* refreshing the user's ID token server-side.
*/
// onTokenRefreshError: (err) => {}
});
};
export default initAuth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment