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
import React from 'react' | |
import App from 'next/app' | |
import { AuthProvider } from 'contexts/auth' | |
import Layout from 'components/layout' | |
class MyApp extends App { | |
render() { | |
const { Component, pageProps } = this.props | |
return ( | |
<AuthProvider> |
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
import React, { createContext, useContext, useState, useEffect } from 'react' | |
import { useRouter } from 'next/router' | |
const AuthContext = createContext() | |
function AuthProvider({ children }) { | |
const { pathname, events } = useRouter() | |
const [user, setUser] = useState() | |
async function getUser() { | |
try { |
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
// From the docs: https://github.com/auth0/nextjs-auth0#user-profile | |
import auth0 from 'contexts/auth0' | |
export default async function me(req, res) { | |
try { | |
await auth0.handleProfile(req, res) | |
} catch (error) { | |
console.error(error) | |
res.status(error.status || 500).end(error.message) | |
} |
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
Projects.getInitialProps = async ({ req }) => { | |
// Prevent unnecessary refetching | |
if (process.browser) { | |
const { projects } = window.__NEXT_DATA__.props.pageProps | |
if (projects && projects.length > 0) { | |
return { projects } | |
} | |
} | |
try { | |
// Have the correct API 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
import { getMDXInfo } from 'utils/get-meta' | |
export default async (req, res) => { | |
if (req.method !== 'GET') { | |
return (res.statusCode = 401) | |
} | |
res.setHeader('Content-Type', 'application/json') | |
try { | |
const { list } = await getMDXInfo('projects') | |
res.status(200).json({ projects: list }) |
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
function Projects() { | |
const [projects, setProjects] = useState([]) | |
const [error, setError] = useState() | |
useEffect(() => { | |
async function fetchProjects() { | |
try { | |
const result = await fetch(`/api/get-projects`) | |
const json = await result.json() | |
setProjects(json.projects) | |
} catch (err) { |
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
const fs = require('fs') | |
const { promisify } = require('util') | |
const YAML = require('yaml') | |
async function getMDXInfo(content) { | |
try { | |
const files = await promisify(fs.readdir)(`./pages/${content}`) | |
const mdx = await files.filter(f => f.includes('.mdx')) | |
let list = await Promise.all( | |
mdx.map(async p => { |
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
[ | |
{ | |
"name": "nextjs-workshop", | |
"size": 299, | |
"title": "nextjs-workshop", | |
"description": "public workshop for getting started with NextJS", | |
"createdAt": "2019-10-27", | |
"type": "github", | |
"tags": ["React", "NextJS"] | |
}, |
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
const frontmatter = require('remark-frontmatter') | |
const withMDX = require('@next/mdx')({ | |
extension: /\.mdx?$/, | |
options: { | |
remarkPlugins: [frontmatter], | |
}, | |
}) | |
module.exports = withMDX({ | |
pageExtensions: ['js', 'jsx', 'mdx'], |
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
... | |
async uploadImageAsync(uri) { | |
let formData = new FormData(); | |
formData.append("query", ` | |
mutation CreateFile($input: CreateFileInput!) { | |
createFile(input: $input) { | |
changedFile { | |
id | |
name |
NewerOlder