-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GP-9: deploy on Netlify #4
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 @@ | ||
/out_publish | ||
/out_functions |
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
# production | ||
/build | ||
/out_functions | ||
/out_publish | ||
|
||
# misc | ||
.DS_Store | ||
|
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,6 @@ | ||
const errors = { | ||
login: 'Не удалось войти', | ||
signup: 'Не удалось зарегистрироваться', | ||
}; | ||
|
||
export default errors; |
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,9 @@ | ||
[build] | ||
command = "yarn build" | ||
functions = "out_functions" | ||
publish = "out_publish" | ||
|
||
[dev] | ||
functions = "out_functions" | ||
publish = "out_publish" | ||
framework = "#static" |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "growth-point", | ||
"name": "growth-points", | ||
"version": "0.1.0", | ||
"engineStrict": true, | ||
"engines": { | ||
|
@@ -8,7 +8,9 @@ | |
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"postbuild": "next-on-netlify", | ||
"start": "next start", | ||
"start-netlify": "netlify dev", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это просто для локального тестирования |
||
"lint": "eslint --ext .ts,.tsx,.js ./", | ||
"analyzer": "cross-env ANALYZE=true yarn build" | ||
}, | ||
|
@@ -21,6 +23,7 @@ | |
"cross-env": "7.0.2", | ||
"firebase": "7.21.0", | ||
"firebase-admin": "9.2.0", | ||
"nanoid": "3.1.12", | ||
"next": "9.5.3", | ||
"preact": "10.5.2", | ||
"preact-render-to-string": "5.1.10", | ||
|
@@ -42,6 +45,8 @@ | |
"eslint-plugin-react": "7.20.3", | ||
"eslint-plugin-react-hooks": "4.0.8", | ||
"husky": "4.3.0", | ||
"netlify-cli": "2.64.1", | ||
"next-on-netlify": "2.4.0", | ||
"typescript": "4.0.3" | ||
}, | ||
"husky": { | ||
|
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 |
---|---|---|
@@ -1,59 +1,53 @@ | ||
import React from 'react'; | ||
import App, { AppContext, AppProps } from 'next/app'; | ||
import 'bulma/css/bulma.css'; | ||
|
||
import App, { AppContext, AppProps, AppInitialProps } from 'next/app'; | ||
import { AuthProvider } from '../context/authContext'; | ||
import endpoints from '../constants/endpoints'; | ||
import { User } from '../types/user'; | ||
import getOriginFromRequest from '../utils/server/getOriginFromRequest'; | ||
import redirectLogin from '../utils/auth/redirect'; | ||
|
||
import 'bulma/css/bulma.css'; | ||
|
||
type MyProps = { | ||
user: User | ||
user?: User | ||
}; | ||
|
||
function MyApp({ | ||
Component, pageProps, user, | ||
}: AppProps & MyProps) { | ||
return ( | ||
<AuthProvider user={user}> | ||
<Component {...pageProps} /> | ||
</AuthProvider> | ||
); | ||
} | ||
|
||
MyApp.getInitialProps = async (appContext: AppContext): Promise<any> => { | ||
const appProps = await App.getInitialProps(appContext); | ||
const MyApp = ({ Component, pageProps, user }: AppProps & MyProps) => ( | ||
<AuthProvider user={user}> | ||
<Component {...pageProps} /> | ||
</AuthProvider> | ||
); | ||
|
||
MyApp.getInitialProps = async (appContext: AppContext): Promise<AppInitialProps & MyProps> => { | ||
const appProps = await App.getInitialProps(appContext); | ||
const { res, req } = appContext.ctx; | ||
|
||
if (!req) return { ...appProps }; | ||
const url = getOriginFromRequest(req); | ||
|
||
const { parse } = await import('cookie'); | ||
const { default: axios } = await import('axios'); | ||
if (!req || !res) { | ||
return { ...appProps }; | ||
} | ||
|
||
const { token } = parse(req.headers.cookie ?? ''); | ||
try { | ||
const { parse } = await import('cookie'); | ||
const { token } = parse(req.headers.cookie ?? ''); | ||
|
||
let user = null; | ||
if (token) { | ||
const { default: getUser } = await import('../utils/firebase/getUser'); | ||
const userData = await getUser(token); | ||
|
||
if (token) { | ||
const { data: userRes, status } = await axios.get(url + endpoints.api.getUser, { | ||
headers: { | ||
token, | ||
}, | ||
}); | ||
if (userData) { | ||
return { ...appProps, user: userData }; | ||
} | ||
|
||
if (status === 200) { | ||
user = userRes; | ||
redirectLogin(req, res); | ||
} else { | ||
redirectLogin(req, res); | ||
} | ||
} else { | ||
|
||
return { ...appProps }; | ||
} catch (e) { | ||
console.error(e); | ||
|
||
redirectLogin(req, res); | ||
} | ||
|
||
return { ...appProps, user }; | ||
return { ...appProps }; | ||
} | ||
}; | ||
|
||
export default MyApp; |
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import firebase from '../../utils/server/firebaseClient'; | ||
import { Hackathon } from '../../types/hackathon'; | ||
import getHackathons from '../../utils/firebase/getHackathons'; | ||
|
||
const getHackathons = async (_: NextApiRequest, res: NextApiResponse) => { | ||
const hackathonsHandler = async (_: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
const hackathonsRef = firebase.database().ref('hackathons'); | ||
const snapshot = await hackathonsRef.once('value'); | ||
const hackathons: Hackathon[] = snapshot.val(); | ||
const hackathons = await getHackathons(); | ||
|
||
res.status(200).json({ hackathons }); | ||
} catch (e) { | ||
res.status(500).json({ error: e.message }); | ||
} | ||
}; | ||
|
||
export default getHackathons; | ||
export default hackathonsHandler; |
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 |
---|---|---|
@@ -1,29 +1,22 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { serialize } from 'cookie'; | ||
import firebaseClient from '../../utils/server/firebaseClient'; | ||
import login from '../../utils/firebase/login'; | ||
import endpoints from '../../constants/endpoints'; | ||
|
||
const login = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const handleLogin = async (req: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
const { email, password } = req.body; | ||
await firebaseClient.auth().setPersistence(firebaseClient.auth.Auth.Persistence.NONE); | ||
const { user, token, expirationTime } = await login(req.body); | ||
|
||
const { user } = await firebaseClient.auth().signInWithEmailAndPassword(email, password); | ||
const tokenResult = await user?.getIdTokenResult(); | ||
res.setHeader('Set-Cookie', serialize('token', token, { | ||
path: endpoints.pages.index, | ||
httpOnly: true, | ||
expires: new Date(expirationTime), | ||
})); | ||
|
||
await firebaseClient.auth().signOut(); | ||
|
||
res.setHeader( | ||
'Set-Cookie', | ||
serialize('token', tokenResult?.token ?? '', { | ||
expires: new Date(tokenResult?.expirationTime ?? ''), | ||
path: '/', | ||
httpOnly: true, | ||
}), | ||
); | ||
res.status(200).json({ user }); | ||
} catch (e) { | ||
res.status(500).json({ error: e.message }); | ||
} | ||
}; | ||
|
||
export default login; | ||
export default handleLogin; |
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { serialize } from 'cookie'; | ||
import endpoints from '../../constants/endpoints'; | ||
|
||
const logout = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const handleLogout = async (_: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
res.setHeader( | ||
'Set-Cookie', | ||
serialize('token', '', { expires: new Date(), path: '/', httpOnly: true }), | ||
); | ||
res.setHeader('Set-Cookie', serialize('token', '', { | ||
path: endpoints.pages.index, | ||
httpOnly: true, | ||
})); | ||
|
||
res.status(200).json({ status: 'OK' }); | ||
} catch (e) { | ||
res.status(500).json({ error: e.message }); | ||
} | ||
}; | ||
|
||
export default logout; | ||
export default handleLogout; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
т.к. взаимодействуем с firebase теперь внутри getInitialProps, нужно явно исключать из бандла (несмотря на проверку req и res), иначе на этапе сборке клиента получаем ошибку (firebase-admin не может работать на клиенте)