remove github authentication. Documentation is now public

Signed-off-by: jffarge <jf@dagger.io>
This commit is contained in:
jffarge 2022-03-29 13:28:45 +02:00
parent ea59c932bb
commit fb10328a2b
9 changed files with 5 additions and 237 deletions

View File

@ -7,7 +7,6 @@
ignore = "false"
[context.deploy-preview]
command = "yarn build:withoutAuth"
ignore = "false"
[[redirects]]
@ -18,21 +17,6 @@
status = 302
force = true
[[redirects]]
from = "/github-proxy/*"
to = "https://github.com/:splat"
status = 200
[[redirects]]
from = "/github-api-proxy/*"
to = "https://api.github.com/:splat"
status = 200
[[redirects]]
from = "/docs-access/*"
to = "https://j20f3pfq11.execute-api.us-east-1.amazonaws.com/Prod/u/:splat"
status = 200
[[redirects]]
from = "/t"
to = "https://api.amplitude.com"

View File

@ -4,17 +4,15 @@
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "OAUTH_ENABLE=false docusaurus start",
"start:withAuth": "OAUTH_ENABLE=true docusaurus start --port=3001",
"build": "OAUTH_ENABLE=true docusaurus build",
"build:withoutAuth": "OAUTH_ENABLE=false docusaurus build",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"start-server": "concurrently \"OAUTH_ENABLE=false yarn docusaurus start --port=3000 --no-open\" \"OAUTH_ENABLE=true yarn docusaurus start --port=3001 --no-open\"",
"start-server": "concurrently \"yarn docusaurus start --port=3000 --no-open\" \"yarn docusaurus start --port=3001 --no-open\"",
"ci": "start-server-and-test 'yarn start-server' '3000|3001' 'yarn run cypress run'"
},
"dependencies": {

View File

@ -1,67 +0,0 @@
import axios from 'axios';
const AxiosInstance = axios.create({
headers: { 'Accept': 'application/vnd.github.v3+json' },
});
function bindApiCall({ url, config, errorMessage }) {
try {
const apiCall = AxiosInstance.get(url, {
...config,
validateStatus: function (status) {
return status < 500; // Resolve only if the status code is less than 500
}
})
return apiCall
} catch (error) {
console.log(errorMessage, error.message)
}
}
async function getAccessToken(code) {
const accessToken = await bindApiCall({
url: `${process.env.REACT_APP_API_PROXY_ENABLE == 'true' ? '/github-proxy' : 'https://github.com'}/login/oauth/access_token`,
config: {
params: {
code,
client_id: process.env.REACT_APP_CLIENT_ID,
client_secret: process.env.REACT_APP_CLIENT_SECRET,
},
errorMessage: 'error getAccessToken'
}
})
return accessToken.data
}
export async function getUser(access_token) {
const user = await bindApiCall({
url: `${process.env.REACT_APP_API_PROXY_ENABLE == 'true' ? '/github-api-proxy' : 'https://api.github.com'}/user`,
config: {
headers: { Authorization: `token ${access_token}` },
},
errorMessage: 'error getUser'
})
return {
login: user.data?.login,
error: user.data?.error_description,
status: user.status
}
}
export async function checkUserCollaboratorStatus(code) {
const { access_token } = await getAccessToken(code)
const { login } = await getUser(access_token)
const isUserCollaborator = await bindApiCall({
url: `${process.env.REACT_APP_API_PROXY_ENABLE == 'true' ? '/docs-access' : 'https://j20f3pfq11.execute-api.us-east-1.amazonaws.com/Prod/u'}/${login}`,
errorMessage: 'error checkUserCollaboratorStatus'
})
return {
permission: isUserCollaborator.data,
login
}
}

View File

@ -1,15 +0,0 @@
import React from "react";
import { GithubLoginButton } from 'react-social-login-buttons';
import style from './DocPageAuthentication.module.css'
export default function DocAuthentication() {
return (
<div data-cy="cy-signin" className={style.container}>
<h1 className={style.h1}>Welcome to the Dagger documentation</h1>
<p>Please Sign In to Github to get access to the doc</p>
<div data-cy="cy-btn-signin">
<GithubLoginButton className={style.btn__github} onClick={() => window.location.href = process.env.REACT_APP_GITHUB_AUTHORIZE_URI} />
</div>
</div>
)
}

View File

@ -1,18 +0,0 @@
.container {
background: url("/img/Dagger_Website_Space_Uranus.png") no-repeat;
background-size: cover;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.btn__github {
width: 240px !important;
border-radius: 0 !important;
}
.btn__github > div {
display: inline-flex !important;
}

View File

@ -1,39 +0,0 @@
import React, { useState, useEffect } from 'react';
import qs from 'querystringify';
import isEmpty from 'lodash/isEmpty';
import NProgress from "nprogress";
import { checkUserCollaboratorStatus } from '../api/github'
import DocPageAuthentication from './DocPageAuthentication';
import DocPageRedirect from './DocPageRedirect';
function DocPageCustom({ location, userAccessStatus, setUserAccessStatus }) {
const [isLoading, setIsLoading] = useState(true)
const [redirectState, setRedirectState] = useState()
const authQuery = qs.parse(location.search);
useEffect(async () => {
NProgress.start()
if (!isEmpty(authQuery?.code) && userAccessStatus === null) { //callback after successful auth with github
const user = await checkUserCollaboratorStatus(authQuery?.code);
setUserAccessStatus(user)
if (user?.permission) {
window.localStorage.setItem('user', JSON.stringify(user));
}
}
NProgress.done();
setIsLoading(false)
}, [])
if(isLoading) return <p>...</p>
if (userAccessStatus?.permission === false) {
return <DocPageRedirect />
}
if (userAccessStatus === null) {
return <DocPageAuthentication />
}
}
export default DocPageCustom

View File

@ -1,29 +0,0 @@
import React, { useEffect, useState } from "react";
import style from './DocPageRedirect.module.css'
export default function DocPageRedirect() {
const [counter, setCounter] = useState(10)
useEffect(() => {
setTimeout(() => window.location.href = process.env.REACT_APP_DAGGER_SITE_URI, 10000)
setInterval(() => setCounter((prevState) => prevState - 1), 1000)
}, [])
return (
<div data-cy="cy-page-redirect" className={`container ${style.wrapper}`}>
<div className={`row ${style.row}`}>
<div className="col col--4 col--offset-2">
<h1 className={style.h1}>Oups!</h1>
<p>It seems you don't have the permission to see Dagger's documentation. But don't worry you can request an Eary Access :). You'll be redirect to Dagger website in {counter} seconds </p>
<p>See you soon !</p>
<br />
<small><strong>If nothing happen, <a href={process.env.REACT_APP_DAGGER_SITE_URI}>click here</a> to go to Dagger website</strong></small>
</div>
<div className="col col--4">
<img src="/img/dagger-astronaute.png" alt="" />
</div>
</div>
</div>
)
}

View File

@ -1,25 +0,0 @@
.wrapper {
background: linear-gradient(180deg, #131226, #0e2b3d);
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: var(--ifm-color-primary-light);
max-width: 100%;
}
.wrapper a {
color: var(--ifm-color-primary-light);
text-decoration: underline;
}
.h1 {
margin-bottom: 2rem;
}
.row {
justify-content: center;
align-content: center;
align-items: center;
}

View File

@ -25,7 +25,6 @@ import {
DocsVersionProvider,
} from '@docusaurus/theme-common';
import Head from '@docusaurus/Head';
import DocPageCustom from "../../components/DocPageCustom"
import amplitude from 'amplitude-js';
function DocPageContent({
@ -140,29 +139,9 @@ function DocPage(props) {
);
// DocPage Swizzle
const [userAccessStatus, setUserAccessStatus] = useState(
(() => {
if (typeof window !== 'undefined')
return JSON.parse(window.localStorage.getItem('user'));
})(),
);
useEffect(() => {
if (userAccessStatus?.login) {
var amplitudeInstance = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, userAccessStatus?.login.toLowerCase(), {
apiEndpoint: `${window.location.hostname}/t`
});
amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname });
if (window?.hj) {
window.hj("identify", userAccessStatus?.login.toLowerCase(), {});
}
}
}, [location.pathname, userAccessStatus])
if (process.env.OAUTH_ENABLE == 'true' && userAccessStatus?.permission !== true) {
return <DocPageCustom location={location} userAccessStatus={userAccessStatus} setUserAccessStatus={setUserAccessStatus} />
}
amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname });
}, [location.pathname])
// End DocPageSwizzle
if (!currentDocRoute) {