Skip to content

Commit

Permalink
Added global config files to setup the core project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinXPN committed Oct 16, 2023
1 parent 24f76c6 commit 30b5fdd
Show file tree
Hide file tree
Showing 17 changed files with 4,605 additions and 3,684 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib
node_modules
.next
.firebase
7 changes: 7 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"projects": {
"default": "next-firebase-mui-starter",
"prod": "next-firebase-mui-starter",
"test": "next-firebase-mui-starter-test"
}
}
109 changes: 93 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,82 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
**/*-key.json

## Project specific files ##
.runtimeconfig.json
test_data/
lib/
firebase-export-*
firebase/tests*
tsconfig.tsbuildinfo

# Next JS
.next/


# IntelliJ
.idea/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Distribution directories
dist/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# dependencies
/node_modules
Expand All @@ -8,28 +86,27 @@
# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem
.env.local
.env.development.local
.env.test.local
.env.production.local

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
# Firebase
.firebase/
firebase/firebase-key.json

# Python
*.ipynb
**/.ipynb_checkpoints/

# vercel
.vercel
# IDE specific
.vscode

# typescript
*.tsbuildinfo
next-env.d.ts
# Sentry Config File
.sentryclirc
62 changes: 62 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"firestore": {
"rules": "firebase/firestore.rules",
"indexes": "firebase/firestore.indexes.json"
},
"hosting": {
"public": ".next",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "firebase/storage.rules"
},
"functions": {
"predeploy": [
"yarn --cwd \"$RESOURCE_DIR\" lint",
"yarn --cwd \"$RESOURCE_DIR\" build"
],
"source": "functions",
"ignore": [
"node_modules",
"test",
"generators",
".git",
".react-email",
"firebase-debug.log",
"firebase-debug.*.log"
]
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
},
"pubsub": {
"port": 8087
}
}
}
Empty file added functions/models/index.ts
Empty file.
26 changes: 26 additions & 0 deletions functions/models/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "models",
"description": "shared models for the whole project",
"version": "0.0.1",
"license": "MIT",
"declarationMap": true,
"composite": true,
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": ["lib/**/*"],
"scripts": {
"lint": "eslint --ext .js,.ts ",
"build": "tsc",
"prepublishOnly": "tsc"
},
"exports": {
".": "./lib/",
"./users": "./lib/users.js"
},
"devDependencies": {
"typescript": "^5",
"@typescript-eslint/parser": "^6",
"eslint": "^8",
"eslint-plugin-import": "^2"
}
}
16 changes: 16 additions & 0 deletions functions/models/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"allowJs": false,
"declaration": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
},
"compileOnSave": true
}
10 changes: 10 additions & 0 deletions functions/models/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface UserInfo {
id: string;
imageUrl?: string;
displayName?: string;
}

export interface UserPreferences {
unsubscribeWeeklyProgress?: boolean;
unsubscribeAnnouncements?: boolean;
}
69 changes: 69 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {NextRequest, NextResponse} from 'next/server';
import {authentication} from "next-firebase-auth-edge/lib/next/middleware";


const commonOptions = {
loginPath: '/api/login',
logoutPath: '/api/logout',
apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY!,
cookieName: 'ProfoundAcademyAuth',
cookieSignatureKeys: [process.env.COOKIE_SECRET_CURRENT!, process.env.COOKIE_SECRET_PREVIOUS!],
cookieSerializeOptions: {
path: '/',
httpOnly: true,
secure: process.env.NEXT_PUBLIC_COOKIE_SECURE === 'true', // Set this to true on HTTPS environments
sameSite: 'lax' as const, // https://github.com/vercel/next.js/discussions/41745#discussioncomment-5408993
maxAge: 12 * 60 * 60 * 24, // twelve days
},
serviceAccount: {
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID!,
clientEmail: process.env.PRIVATE_FIREBASE_CLIENT_EMAIL!,
// Using JSON to handle newline problems when storing the key as a secret in Vercel
// https://github.com/vercel/vercel/issues/749#issuecomment-707515089
privateKey: JSON.parse(process.env.PRIVATE_FIREBASE_PRIVATE_KEY!),
},
};


export async function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname;

// `/_next/` and `public/demo/*` are ignored by the watcher, but we need to ignore other files in `public` manually
if ([
'/manifest.json',
'/robots.txt',
'/sitemap.xml',
'/logo192.png',
'/logo512.png',
'/logo.svg',
].includes(pathname))
return;
console.log('pathname:', pathname);

// Handle authentication
if ([commonOptions.loginPath, commonOptions.logoutPath].includes(pathname)) {
console.log('handling auth:', pathname);
return authentication(request, {
...commonOptions,
handleValidToken: async ({ token, decodedToken }) => {
console.log('Successfully authenticated', { token, decodedToken });
return NextResponse.next();
},
handleInvalidToken: async () => {
console.log('Not authenticated or token expired');
return NextResponse.next();
},
handleError: async (error) => {
console.error('Oops, this should not have happened.', { error });
return NextResponse.next();
},
});
}
}

export const config = {
matcher: [
// Skip all internal paths (_next, _vercel, assets, etc.)
'/((?!_next/static|_next/image|_vercel/insights|monitoring|demo|assets|favicon.ico).*)',
],
}
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
48 changes: 45 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const {withSentryConfig} = require('@sentry/nextjs');

module.exports = nextConfig
module.exports = withSentryConfig({
reactStrictMode: true,
experimental: {
serverActions: true,
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"]
});

return config;
},
},

// Injected content via Sentry wizard below
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

// Suppresses source map uploading logs during build
silent: true,
org: process.env.NEXT_PUBLIC_SENTRY_ORG,
project: process.env.NEXT_PUBLIC_SENTRY_PROJECT,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
});
Loading

0 comments on commit 30b5fdd

Please sign in to comment.