This repository has been archived by the owner on Aug 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
f49a4ee
commit 6e78870
Showing
1 changed file
with
39 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,39 @@ | ||
import { exchangeTicketForToken } from '@/utils/auth'; | ||
import { useRouter } from 'next/router'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
const Login = () => { | ||
const { query, replace, isReady } = useRouter(); | ||
const timeCloseRegister = new Date('2022-07-24T12:00:00+07:00'); | ||
const time = new Date(); | ||
const handleLogin = useCallback(async (ticket: string) => { | ||
const token = await exchangeTicketForToken(ticket); | ||
localStorage.setItem('token', JSON.stringify(token)); | ||
|
||
window.location.href = '/register'; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (isReady) { | ||
if (query?.ticket) { | ||
if (time >= timeCloseRegister) { | ||
//window.location.href = '/registerClose'; | ||
} else { | ||
handleLogin(query.ticket as string); | ||
} | ||
} else { | ||
replace('/'); | ||
if (time < timeCloseRegister) { | ||
window.location.href = '/baan-selection'; | ||
} | ||
} | ||
} | ||
}, [query, replace, handleLogin, isReady]); | ||
|
||
return ( | ||
<h1>hi</h1> | ||
//content | ||
); | ||
}; | ||
|
||
export default Login; |