Skip to content

Commit

Permalink
feat: login logic for members page
Browse files Browse the repository at this point in the history
  • Loading branch information
Esinko committed Dec 18, 2022
1 parent 8913c0f commit db0374c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
5 changes: 1 addition & 4 deletions components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ export function Header({pages, activePath}) {
<Logo className={styles.logo} showBeta link />
<Navigation className={styles.navigation} pages={pages} activePath={activePath} open={open} setOpen={setOpen} />
<a className={styles.navButtons}>
{process.env.NODE_ENV != "production" ?
(
<a onClick={() => setLoginVisible(true)}>
<a onClick={() => setLoginVisible(true)} style={{ display: process.env.NODE_ENV != "production" ? "block" : "none"}}>
<CapsuleButton className={styles.button} small secondary>
<IoMdKey />
Jäsensivut
</CapsuleButton>
</a>
) : null}
<a href="https://discord.testausserveri.fi">
<CapsuleButton className={styles.button} small>
<ButtonIcon src={DiscordIcon} />
Expand Down
35 changes: 30 additions & 5 deletions components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,44 @@ const DynamicTestausid = dynamic(() => import('@testausserveri/react-testausid')
})

import FadeIn from 'react-fade-in';
import { apiServer } from '../../utils/api';

export function LoginDialog({ onClose }) {
const accept = [
'members',
'discord'
]
const client = '181937620043556561658238287560538816854'
const scopes = ['id', 'account']
const scopes = ['id', 'account', 'contact']

return <DynamicTestausid onClose={onClose} accept={accept} client={client} scopes={scopes} onClick={e => {
e.preventDefault()
e.stopPropagation()
}} />
return <DynamicTestausid
onClose={onClose}
accept={accept}
client={client}
scopes={scopes}
onClick={e => {
e.preventDefault()
e.stopPropagation()
}}
onlyToken={true}
onLogin={token => {
fetch(`${apiServer}/v1/members/login`, {
method: "POST",
body: JSON.stringify(token),
redirect: "manual",
headers: {
"Content-Type": "application/json"
}
}).then(async res => {
if (res.status === 200) {
if (document.cookie.includes("code=")) document.cookie = document.cookie.replace(/code=(.{1,}|);( |)domain=\.testausserveri\.fi;( |)path=\/(;|$)/, "")
document.cookie += `code=${await res.text()};domain=.testausserveri.fi;path=/;`
window.location.href = `${apiServer}/v1/members`
}
else console.error("Failed to login.") // TODO: display to user
})
}}
/>
}

export function LoginView({visible, setLoginVisible}) {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@skyra/discord-components-react": "^3.1.1",
"@splinetool/react-spline": "^2.2.1",
"@splinetool/runtime": "^0.9.53",
"@testausserveri/react-testausid": "^1.3.3",
"@testausserveri/react-testausid": "^1.3.4",
"@tippyjs/react": "^4.2.6",
"hamburger-react": "^2.4.1",
"next": "^12.1.4",
Expand Down

1 comment on commit db0374c

@vercel
Copy link

@vercel vercel bot commented on db0374c Dec 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.