mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-25 02:36:20 +01:00
39 lines
784 B
JavaScript
39 lines
784 B
JavaScript
import { useEffect } from 'react';
|
|
import debug from 'debug';
|
|
import { useRouter } from 'next/router';
|
|
import { setItem } from 'next-basics';
|
|
import { AUTH_TOKEN } from 'lib/constants';
|
|
import useApi from 'hooks/useApi';
|
|
import { setUser } from 'store/app';
|
|
|
|
const log = debug('umami:sso');
|
|
|
|
export default function SingleSignOnPage() {
|
|
const router = useRouter();
|
|
const { get } = useApi();
|
|
const { token, url } = router.query;
|
|
|
|
useEffect(() => {
|
|
async function verify() {
|
|
setItem(AUTH_TOKEN, token);
|
|
|
|
const { ok, data } = await get('/auth/verify');
|
|
|
|
if (ok) {
|
|
log(data);
|
|
setUser(data);
|
|
|
|
if (url) {
|
|
await router.push(url);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (token) {
|
|
verify();
|
|
}
|
|
}, [token]);
|
|
|
|
return null;
|
|
}
|