Skip to content

Instantly share code, notes, and snippets.

@vpaladino778
Created December 17, 2021 14:11
Show Gist options
  • Save vpaladino778/1bf0448958762d14ba82f98e49418309 to your computer and use it in GitHub Desktop.
Save vpaladino778/1bf0448958762d14ba82f98e49418309 to your computer and use it in GitHub Desktop.
// ./initAuth.js
import { init } from 'next-firebase-auth';
const initAuth = () => {
init({
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: 'sweep-7359d',
clientEmail: 'example-abc123@my-example-app.iam.gserviceaccount.com',
// 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: 'AIzaSyCkIzSv37sLpgexi6tTkHN2Vrb223q3J5Q', // required
authDomain: 'sweep-7359d.firebaseapp.com',
databaseURL: 'https://my-example-app.firebaseio.com',
projectId: 'sweep-7359d',
},
cookies: {
name: 'ExampleApp', // 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: true, // 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