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

Check validity of authentication token #126

Open
NicolasMahe opened this issue Jan 20, 2023 · 0 comments
Open

Check validity of authentication token #126

NicolasMahe opened this issue Jan 20, 2023 · 0 comments

Comments

@NicolasMahe
Copy link
Member

NicolasMahe commented Jan 20, 2023

The function setAuthenticationToken should first check if the token is valid (not expired) and then set it.

We already have the logic implemented in the currentAddress:

const [authenticationToken, setAuthenticationToken] = useState<string>()
const client = useMemo(() => new GraphQLClient(endpoint), [endpoint])
const sdk = useMemo(() => getSdk(client), [client])
const currentAddress = useMemo(() => {
if (!authenticationToken) return null
const res = decode<JwtPayload & { address: string }>(authenticationToken)
if (res.exp && res.exp < Math.ceil(Date.now() / 1000)) return null

We could add a new public function isAuthenticationTokenValid that could be use in different places and also by the apps

Existing logic in https://github.com/liteflow-labs/admin/blob/main/session.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant