-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prabhat Pal
committed
Jan 27, 2021
1 parent
9f60f5e
commit ee8b7ee
Showing
30 changed files
with
4,583 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": [ | ||
"babel-plugin-transform-typescript-metadata", | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ | ||
"legacy": true | ||
} | ||
], | ||
[ | ||
"@babel/plugin-proposal-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"babel-plugin-parameter-decorator" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
NEXT_PUBLIC_MAPBOX_API_TOKEN="" | ||
|
||
NEXT_PUBLIC_FIREBASE_API_KEY="" | ||
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="" | ||
NEXT_PUBLIC_FIREBASE_PROJECT_ID="" | ||
FIREBASE_CLIENT_EMAIL="" | ||
FIREBASE_PRIVATE_KEY="" | ||
|
||
CLOUDINARY_SECRET="" | ||
NEXT_PUBLIC_CLOUDINARY_KEY="" | ||
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME="" | ||
|
||
DATABASE_URL="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2020": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"tslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:import/errors", | ||
"plugin:import/warnings", | ||
"plugin:import/typescript", | ||
"plugin:react-hooks/recommended", | ||
"plugin:tailwind/recommended", | ||
"prettier", | ||
"prettier/react", | ||
"prettier/@typescript-eslint", | ||
"plugin:prettier/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "tsconfig.json", | ||
"ecmaVersion": 2020, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint", "@typescript-eslint/tslint", "import"], | ||
"rules": { | ||
"react/react-in-jsx-scope": "off", | ||
"react/prop-types": "off", | ||
"react/display-name": "off", | ||
"react-hooks/exhaustive-deps": "off", | ||
"no-unused-vars": "warn", | ||
"prettier/prettier": "error", | ||
"import/no-unresolved": "off", | ||
"no-process-env": "off", | ||
"no-undef": "warn", | ||
"css.lint.unknownAtRules": "ignore" | ||
}, | ||
"globals": { | ||
"React": "writable" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": false, | ||
"jsxSingleQuote": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"css.lint.unknownAtRules": "ignore" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
declare namespace NodeJS { | ||
export interface ProcessEnv { | ||
NEXT_PUBLIC_MAPBOX_API_TOKEN: string; | ||
NEXT_PUBLIC_FIREBASE_API_KEY: string; | ||
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: string; | ||
NEXT_PUBLIC_FIREBASE_PROJECT_ID: string; | ||
FIREBASE_CLIENT_EMAIL: string; | ||
FIREBASE_PRIVATE_KEY: string; | ||
CLOUDINARY_SECRET: string; | ||
NEXT_PUBLIC_CLOUDINARY_KEY: string; | ||
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME: string; | ||
DATABASE_URL: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
|
||
declare module "cloudinary-react"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { AppProps } from "next/app"; | ||
import { AuthProvider } from "src/auth/useAuth"; | ||
import Layout from "src/components/Layout"; | ||
import "../styles/tailwind.scss"; | ||
|
||
function MyApp({ Component, pageProps }: AppProps) { | ||
return ( | ||
<AuthProvider> | ||
<Layout> | ||
<Component {...pageProps} /> | ||
</Layout> | ||
</AuthProvider> | ||
); | ||
} | ||
|
||
export default MyApp; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Layout from "src/components/Layout"; | ||
|
||
export const Home = () => { | ||
return ( | ||
<> | ||
<div>Hello</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import firebase from "firebase/app"; | ||
import "firebase/auth"; | ||
|
||
const config = { | ||
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY, | ||
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN, | ||
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID, | ||
}; | ||
|
||
const initFirebase = () => { | ||
if (!firebase.apps.length) { | ||
firebase.initializeApp(config); | ||
} | ||
}; | ||
|
||
export default initFirebase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Cookies from "js-cookie"; | ||
|
||
export const getToken = () => { | ||
Cookies.get("token"); | ||
}; | ||
|
||
export const setToken = (token: string) => { | ||
Cookies.set("token", token, { expires: 1 / 24 }); | ||
}; | ||
|
||
export const removeToken = () => { | ||
Cookies.remove("token"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { createContext, FC, useContext, useEffect, useState } from "react"; | ||
import initFirebase from "./initFirebase"; | ||
import firebase from "firebase/app"; | ||
import { useRouter } from "next/router"; | ||
import { removeToken, setToken } from "./token"; | ||
|
||
initFirebase(); | ||
|
||
interface IAuthContext { | ||
user: firebase.User | null; | ||
logout: () => void; | ||
authenticated: boolean; | ||
} | ||
|
||
const AuthContext = createContext<IAuthContext>({ | ||
user: null, | ||
logout: () => null, | ||
authenticated: false, | ||
}); | ||
|
||
export const AuthProvider: FC = ({ children }) => { | ||
const [user, setUser] = useState<firebase.User | null>(null); | ||
const router = useRouter(); | ||
|
||
const logout = () => { | ||
firebase | ||
.auth() | ||
.signOut() | ||
.then(() => router.push("/")) | ||
.catch((err) => console.error(err)); | ||
}; | ||
|
||
useEffect(() => { | ||
const cancelAuthListner = firebase.auth().onIdTokenChanged(async (user) => { | ||
if (user) { | ||
const token = await user.getIdToken(); | ||
setToken(token); | ||
setUser(user); | ||
} else { | ||
removeToken(); | ||
setUser(null); | ||
} | ||
}); | ||
return () => { | ||
cancelAuthListner(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<AuthContext.Provider value={{ user, logout, authenticated: !!user }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
export const useAuth = () => { | ||
return useContext(AuthContext); | ||
}; |
Oops, something went wrong.