Skip to content

Commit

Permalink
feat: PAT authentication (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
diivi authored Apr 22, 2023
1 parent 5828e20 commit e726a93
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 15 deletions.
11 changes: 10 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dependencies": {
"@types/chrome": "^0.0.231",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react-dom": "^18.0.0",
"react-icons": "^4.8.0"
},
"devDependencies": {
"@crxjs/vite-plugin": "^1.0.14",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function App() {
}, []);

return (
<div className="p-4">
<div className="p-4 bg-slate-800">
{renderedPage === "start" ? (
<Start setRenderedPage={setRenderedPage} />
) : renderedPage === "home" ? (
Expand Down
22 changes: 22 additions & 0 deletions src/assets/opensauced-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ interface HomeProps {
}

function Home({ osAccessToken, setRenderedPage }: HomeProps) {
return <div>Home</div>;
return (
<div>
<p className="text-white">Home</p>
</div>
);
}

export default Home;
6 changes: 5 additions & 1 deletion src/pages/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from "react";

function Loading() {
return <div>Loading</div>;
return (
<div>
<p className="text-white">Loading...</p>
</div>
);
}

export default Loading;
65 changes: 59 additions & 6 deletions src/pages/signin.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
import React from "react";
import { checkTokenValidity } from "../utils/fetchOpenSaucedApiData";
import { BiArrowBack, BiInfoCircle } from "react-icons/bi";

interface SignInProps {
setRenderedPage: (page: string) => void;
}

function SignIn({ setRenderedPage }: SignInProps) {
return <div>
<h1>Sign In</h1>
<p>Sign in with your PAT</p>
<input type="text" />
<button onClick={() => setRenderedPage("home")}>Sign In</button>
</div>;
const [token, setToken] = React.useState("");

const authenticateUser = (token: string) => {
if (token === "") {
alert("Please enter a valid token");
return;
}
checkTokenValidity(token)
.then((valid) => {
if (valid) {
chrome.storage.sync.set({ "os-access-token": token }, () => {
setRenderedPage("home");
});
} else {
alert("Token is invalid");
}
})
.catch((err) => {
console.log(err);
alert("An error occurred while authenticating");
});
};

return (
<div>
<BiArrowBack
className="text-orange cursor-pointer text-2xl"
onClick={() => setRenderedPage("start")}
/>
<h1 className="text-white text-2xl font-bold my-2">Sign In</h1>
<p className="mb-2 text-gray-300 text-sm">
Enter your Personal Access Token to sign in.
<BiInfoCircle
title="Learn how to obtain a Personal Access Token"
className="inline-block ml-1 text-gray-400 align-middle cursor-pointer"
onClick={() =>
window.open(
"https://docs.opensauced.pizza/contributing/set-up-authentication/",
"_blank"
)
}
/>
</p>
<input
type="text"
className="p-1.5 rounded-md mb-2 outline-none"
onChange={(e) => setToken(e.target.value)}
/>
<button
className="bg-orange border-none rounded-md text-white font-bold py-2 px-4 cursor-pointer
bg-gradient-to-r from-[#e67e22] to-[#d35400] mt-2"
onClick={() => authenticateUser(token)}
>
Sign In
</button>
</div>
);
}

export default SignIn;
23 changes: 19 additions & 4 deletions src/pages/start.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import OpenSaucedLogo from "../assets/opensauced-logo.svg";

interface StartProps {
setRenderedPage: (page: string) => void;
Expand All @@ -7,9 +7,24 @@ interface StartProps {
function Start({ setRenderedPage }: StartProps) {
return (
<div>
<h1>OpenSauced</h1>
<p>Welcome Text</p>
<button onClick={() => setRenderedPage("signin")}>Get Started</button>
<img src={OpenSaucedLogo} alt="Open Sauced Logo" />
<p className="my-4 text-base font-bold text-white leading-5">
Welcome to the{" "}
<a
href="https://opensauced.pizza/"
className="text-orange no-underline"
>
OpenSauced
</a>{" "}
browser extension.
</p>
<button
className="bg-orange border-none rounded-md text-white font-bold py-2 px-4 cursor-pointer
bg-gradient-to-r from-[#e67e22] to-[#d35400]"
onClick={() => setRenderedPage("signin")}
>
Get Started
</button>
</div>
);
}
Expand Down

0 comments on commit e726a93

Please sign in to comment.