Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend adjustements #35

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frontend/src/features/auth/api/fetchUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchApi } from '@/api/fetchApi'
import { type ApiUser } from './ApiUser'

/**
* fetch the logged in user from the api.
* fetch the logged-in user from the api.
*
* If the user is not logged in, the api returns a 401 error.
* Here our wrapper just returns false in that case, without triggering an error:
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/features/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { useUser } from './api/useUser'
export { authUrl } from './utils/authUrl'
export { logoutUrl } from './utils/logoutUrl'
5 changes: 5 additions & 0 deletions src/frontend/src/features/auth/utils/logoutUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { apiUrl } from '@/api/apiUrl'

export const logoutUrl = () => {
return apiUrl('/logout')
}
7 changes: 3 additions & 4 deletions src/frontend/src/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { css } from '@/styled-system/css'
import { flex } from '@/styled-system/patterns'
import { apiUrl } from '@/api/apiUrl'
import { A, Badge, Text } from '@/primitives'
import { useUser } from '@/features/auth/api/useUser'
import { authUrl, logoutUrl, useUser } from '@/features/auth'

export const Header = () => {
const { user, isLoggedIn } = useUser()
Expand Down Expand Up @@ -31,11 +30,11 @@ export const Header = () => {
</Text>
</div>
<div>
{isLoggedIn === false && <A href={apiUrl('/authenticate')}>Login</A>}
{isLoggedIn === false && <A href={authUrl()}>Login</A>}
{!!user && (
<p className={flex({ gap: 1, align: 'center' })}>
<Badge>{user.email}</Badge>
<A href={apiUrl('/logout')} size="small">
<A href={logoutUrl()} size="small">
Logout
</A>
</p>
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/src/routes/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { A, Button, Italic, P, Div, H, Box } from '@/primitives'
import { useUser } from '@/features/auth'
import { apiUrl } from '@/api/apiUrl'
import { authUrl, useUser } from '@/features/auth'
import { navigateToNewRoom } from '@/features/rooms'
import { Screen } from '@/layout/Screen'

Expand All @@ -19,7 +18,7 @@ export const Home = () => {
</Button>
) : (
<p>
<A href={apiUrl('/authenticate')}>
<A href={authUrl()}>
Login to create a conference call
</A>
</p>
Expand Down
Loading