Skip to content

Commit

Permalink
feat: makde login optional
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalPawar1010 committed Jul 17, 2024
1 parent 8a5fb3b commit ee1f37a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "jest"
},
"dependencies": {
"@pieces.app/pieces-os-client": "^2.0.0-2",
"@pieces.app/pieces-os-client": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
Expand Down
43 changes: 25 additions & 18 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,26 @@ export function App(): React.JSX.Element {
const [selectedIndex, setSelectedIndex] = useState<number>(-1);
const [error, setError] = useState(null);

const [userName, setUserName] = useState(null);

const [isLoggedIn, setIsLoggedIn] = useState(false); // State to track login status


// Function to handle user login
const loginUser = async () => {
try {
// Call the signIntoOS() method to initiate the login process
await osApi.signIntoOS();
const userDetails = await osApi.signIntoOS();
setUserName(userDetails.name);
setIsLoggedIn(true); // Update login status

} catch (error) {
console.error("Error logging in:", error);
// Handle login error
}
};


// Function to handle user logout
const logoutUser = async () => {
try {
Expand Down Expand Up @@ -209,12 +214,25 @@ export function App(): React.JSX.Element {

return (
<>
{ isLoggedIn ? (
<div className="container">
<div style={{ display: "flex", justifyContent: "space-between" }}>
<h1 style={{ textAlign: "left" }}>Welcome to Your own Copilot</h1>
<button className="logoutBtn" onClick={logoutUser}>Logout</button>
</div>
{isLoggedIn && userName ? (
<div style={{ display: "flex", justifyContent: "space-between" }}>
<h1 style={{ textAlign: "left" }}>Welcome to Your own Copilot, {userName}</h1>
<button className="logoutBtn " onClick={logoutUser}>Logout</button>
</div>
) : (
<div style={{ display: "flex", justifyContent: "space-between" }}>
<h2 style={{ textAlign: "left" }}>Please Login to use Pieces Copilot</h2>
<button
className="loginBtn "
onClick={loginUser}
>
Login
</button>
</div>
)}


<div className="container">
<Header isConnected={ !error} />
{error && <div className="error-container"> Pieces OS is not running in the background. Click You're Not Connected to connect </div>}
<div className="flex-container">
Expand Down Expand Up @@ -279,17 +297,6 @@ export function App(): React.JSX.Element {
<CopilotChat />
</div>
</div>
):(
<div style={{ display: "flex", justifyContent: "space-between" }}>
<h1 style={{ textAlign: "left" }}>Please Login to use Pieces Copilot</h1>
<button
className="loginBtn"
onClick={loginUser}
>
Login
</button>
</div>
)}
</>
);
}
10 changes: 6 additions & 4 deletions src/app/global.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto"> */
.loginBtn {
font-size: large;
font-size: medium;
color: white;
height: 48px; /* Adjust height as needed */
border-radius: 10px;
border: none;
padding: 0 40px;
padding: 6px 12px;
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -14,12 +14,12 @@
background-color: green;
}
.logoutBtn {
font-size: large;
font-size: medium;
color: white;
height: 48px; /* Adjust height as needed */
border-radius: 10px;
border: none;
padding: 0 40px;
padding: 6px 12px;
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -28,6 +28,8 @@
background-color: red;
}



html {
font-family: "Roboto", sans-serif;
}
Expand Down

0 comments on commit ee1f37a

Please sign in to comment.