Skip to content

Commit

Permalink
add login refresh flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ParadoxZero committed Aug 13, 2024
1 parent b927c23 commit c459f56
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions ui/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,63 @@ import React from 'react'
import ReactDOM from 'react-dom/client'

import './main.css'
import { Button, Card, Flex, Typography } from 'antd'
import { GithubOutlined, GoogleOutlined } from '@ant-design/icons'
import { Button, Card, Flex, Spin, Typography } from 'antd'
import { GithubOutlined, GoogleOutlined, Loading3QuartersOutlined, LoadingOutlined } from '@ant-design/icons'


class App extends React.Component {
interface AppState {
is_loading: boolean;
}
class App extends React.Component<{}, AppState> {
constructor(props: {}) {
super(props)
this.state = {
is_loading: true
}
}

componentDidMount(): void {
fetch('/.auth/refresh').then((response) => {
if (response.ok) {
window.location.href = '/index.html'
}
}).finally(() => {
this.setState({ is_loading: false })
});
}

renderCallToAction() {
if (this.state.is_loading) {
return (
<Spin size='large' indicator={<LoadingOutlined />} />
)
} else {
(
<>
<Button type='primary'
style={{ backgroundColor: '#f5222d' }}
href='.auth/login/google?post_login_redirect_uri=/index.html&access_type=offline'
size='large' block icon={<GoogleOutlined />}>
Login With Google
</Button>
<Button type='primary'
style={{ backgroundColor: '#262626' }}
href='.auth/login/github?post_login_redirect_uri=/index.html'
size='large' block icon={<GithubOutlined />}>
Login With Github
</Button>
</>
)
}
}
render(): React.ReactNode {
return (
<>
<Flex vertical style={{ height: '100vh', width: '100vw', backgroundColor: '#fafafa' }} align='center' justify='center'>
<Card bordered style={{ width: 300 }} hoverable>
<Flex justify='center' align='center' vertical gap={20}>
<Typography.Title level={1}>BudgetBud</Typography.Title>
<Button type='primary'
style={{ backgroundColor: '#f5222d' }}
href='.auth/login/google?post_login_redirect_uri=/index.html'
size='large' block icon={<GoogleOutlined />}>
Login With Google
</Button>
<Button type='primary'
style={{ backgroundColor: '#262626' }}
href='.auth/login/github?post_login_redirect_uri=/index.html'
size='large' block icon={<GithubOutlined />}>
Login With Github
</Button>
{this.renderCallToAction()}
</Flex>
</Card >
</Flex>
Expand Down

0 comments on commit c459f56

Please sign in to comment.