-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81e38d3
commit a6ab1fc
Showing
5 changed files
with
6,176 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.astro/ | ||
dist/ | ||
src/env.d.ts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = { | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:astro/recommended', | ||
'plugin:jsx-a11y/recommended', | ||
'plugin:typescript-sort-keys/recommended', | ||
], | ||
overrides: [ | ||
{ | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
'plugin:@typescript-eslint/strict', | ||
], | ||
files: ['*.astro'], | ||
parser: 'astro-eslint-parser', | ||
parserOptions: { | ||
parser: '@typescript-eslint/parser', | ||
extraFileExtensions: ['.astro'], | ||
}, | ||
rules: { | ||
// TODO: Investigate?? :( | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'deprecation/deprecation': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'], | ||
}, | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: true, | ||
tsconfigRootDir: __dirname, | ||
}, | ||
plugins: [ | ||
'@typescript-eslint', | ||
'astro', | ||
'deprecation', | ||
'jsx-a11y', | ||
'simple-import-sort', | ||
'typescript-sort-keys', | ||
], | ||
root: true, | ||
rules: { | ||
'simple-import-sort/imports': 'error', | ||
'simple-import-sort/exports': 'error', | ||
'deprecation/deprecation': 'error', | ||
|
||
'@typescript-eslint/no-misused-promises': 'off', | ||
'@typescript-eslint/consistent-type-definitions': 'off', | ||
'@typescript-eslint/no-floating-promises': 'off', | ||
'typescript-sort-keys/interface': 'off', | ||
|
||
// Stylistic concerns that don't interfere with Prettier | ||
'padding-line-between-statements': 'off', | ||
|
||
'@typescript-eslint/padding-line-between-statements': [ | ||
'error', | ||
{ blankLine: 'always', next: '*', prev: 'block-like' }, | ||
], | ||
}, | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { AuthProvider, useAuthInfo, useLogoutFunction, useRedirectFunctions } from './propelauth'; | ||
|
||
import '@propelauth/base-elements/dist/default.css'; | ||
import { useEffect, useState } from 'react'; | ||
import { env } from '../config'; | ||
|
||
export function Account() { | ||
return ( | ||
<AuthProvider authUrl={env.PUBLIC_AUTH_URL}> | ||
<AccountInteral /> | ||
</AuthProvider> | ||
); | ||
} | ||
|
||
function AccountInteral() { | ||
const auth = useAuthInfo(); | ||
const logoutFn = useLogoutFunction(); | ||
const { redirectToCreateOrgPage, redirectToOrgPage } = useRedirectFunctions(); | ||
|
||
const [selectedOrgId, setSelectedOrgId] = useState(''); | ||
|
||
if (auth.loading) { | ||
return <>Loading...</>; | ||
} | ||
if (auth.user === null) { | ||
return ( | ||
<> | ||
<h1 className="text-2xl font-bold text-center">Not logged in</h1> | ||
<a href="/login" className="px-4 py-2 bg-blue-500 text-white rounded"> | ||
Login | ||
</a> | ||
<a href="/signup" className="ml-2 px-4 py-2 bg-blue-500 text-white rounded"> | ||
Sign up | ||
</a> | ||
</> | ||
); | ||
} | ||
return ( | ||
<> | ||
<p>The User is logged in</p> | ||
<button className="px-4 py-2 bg-blue-500 text-white rounded" onClick={() => logoutFn(true)}> | ||
Click here to log out | ||
</button> | ||
<button | ||
className="px-4 py-2 bg-blue-500 text-white rounded ml-2" | ||
onClick={() => redirectToOrgPage()} | ||
> | ||
Manage orgs | ||
</button> | ||
<button | ||
className="px-4 py-2 bg-blue-500 text-white rounded ml-2" | ||
onClick={() => redirectToCreateOrgPage()} | ||
> | ||
Create org | ||
</button> | ||
<div> | ||
My orgs: | ||
{auth.orgHelper.getOrgs().map((org) => { | ||
console.log(org); | ||
return ( | ||
<div key={org.orgId} className="ml-2"> | ||
<button | ||
onClick={() => { | ||
setSelectedOrgId(org.orgId); | ||
}} | ||
> | ||
Select <b>{org.orgName}</b> | ||
</button> | ||
<br /> | ||
</div> | ||
); | ||
})} | ||
{selectedOrgId && <Organizations token={auth.accessToken} orgId={selectedOrgId} />} | ||
</div> | ||
<details> | ||
<summary className="cursor-pointer">Debug</summary> | ||
{JSON.stringify(auth)} | ||
</details> | ||
</> | ||
); | ||
} | ||
|
||
type User = { | ||
userId: string; | ||
email: string; | ||
}; | ||
|
||
const Organizations = (props: { token: string; orgId: string }) => { | ||
const [users, setUsers] = useState<User[]>([]); | ||
const [status, setStatus] = useState<'loading' | 'error' | 'success'>('loading'); | ||
useEffect(() => { | ||
setStatus('loading'); | ||
setUsers([]); | ||
fetch('/api/orgs/' + props.orgId, { | ||
headers: { | ||
Authorization: 'Bearer ' + props.token, | ||
}, | ||
}) | ||
.then( | ||
(res) => | ||
res.json() as Promise<{ | ||
users: User[]; | ||
}> | ||
) | ||
.then((res) => res.users) | ||
.then(setUsers) | ||
.then(() => setStatus('success')) | ||
.catch(() => { | ||
setStatus('error'); | ||
}); | ||
}, [props.orgId]); | ||
return ( | ||
<div> | ||
Users: {status === 'loading' && 'Loading...'} | ||
{status === 'error' && 'Error'} | ||
{status === 'success' && | ||
users.map((user) => { | ||
return <div key={user.userId}>{user.email}</div>; | ||
})} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.