From 590304cecedc30e82ae42e8d80359c7931365ad3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 22 Dec 2018 09:35:01 -0500 Subject: [PATCH] auth stuff --- site/src/components/inline-svg.html | 35 +++++++++++ site/src/routes/auth/me.json.js | 9 +++ site/src/routes/gist/[id].js | 10 +++- site/src/routes/index.html | 2 +- .../_components/AppControls/UserMenu.html | 59 ++++++++++++------- .../repl/_components/AppControls/index.html | 8 ++- site/src/routes/repl/index.html | 26 ++++++-- site/src/user.js | 13 +++- site/static/workers/bundler.js | 12 ++-- 9 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 site/src/routes/auth/me.json.js diff --git a/site/src/components/inline-svg.html b/site/src/components/inline-svg.html index 99b3a0b9ec..e4dc0e232f 100644 --- a/site/src/components/inline-svg.html +++ b/site/src/components/inline-svg.html @@ -102,4 +102,39 @@ + + + + + + + + + + \ No newline at end of file diff --git a/site/src/routes/auth/me.json.js b/site/src/routes/auth/me.json.js new file mode 100644 index 0000000000..122be622a8 --- /dev/null +++ b/site/src/routes/auth/me.json.js @@ -0,0 +1,9 @@ +export function get(req, res) { + if (!req.session.passport || !req.session.passport.user) { + res.send(null); + return; + } + + const { id, username, displayName, photo } = req.session.passport && req.session.passport.user; + res.send({ id, username, displayName, photo }); +} \ No newline at end of file diff --git a/site/src/routes/gist/[id].js b/site/src/routes/gist/[id].js index 91a362e2aa..e20acac018 100644 --- a/site/src/routes/gist/[id].js +++ b/site/src/routes/gist/[id].js @@ -4,7 +4,15 @@ import { body } from './_utils.js'; export async function get(req, res) { const { id } = req.params; - const r = await fetch(`https://api.github.com/gists/${id}`); + const headers = {}; + const user = req.session.passport && req.session.passport.user; + if (user) { + headers.Authorization = `token ${user.token}`; + } + + const r = await fetch(`https://api.github.com/gists/${id}`, { + headers + }); res.writeHead(r.status, { 'Content-Type': 'application/json' diff --git a/site/src/routes/index.html b/site/src/routes/index.html index 994c961163..f058be3a82 100644 --- a/site/src/routes/index.html +++ b/site/src/routes/index.html @@ -131,7 +131,7 @@
  • -

    No virtual DOM overhead

    +

    No virtual DOM

    Svelte compiles your code to tiny, framework-less vanilla JS — your app starts fast and stays fast

    learn more diff --git a/site/src/routes/repl/_components/AppControls/UserMenu.html b/site/src/routes/repl/_components/AppControls/UserMenu.html index 7bcd8f0645..2fc8a9577e 100644 --- a/site/src/routes/repl/_components/AppControls/UserMenu.html +++ b/site/src/routes/repl/_components/AppControls/UserMenu.html @@ -1,7 +1,7 @@