add: verification page
This commit is contained in:
parent
b4d3d51d8c
commit
3ebae75689
@ -1,15 +1,22 @@
|
|||||||
import styles from "../styles/Home.module.css";
|
import styles from "../styles/Home.module.css";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
interface AuthResponse {
|
||||||
|
authUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const handleSigninWithTwitter = async () => {
|
const handleSignInWithTwitter = async () => {
|
||||||
const { authUrl } = await (await fetch("/api/auth")).json();
|
const response: AuthResponse = await (await fetch("/api/auth")).json();
|
||||||
|
|
||||||
window.open(authUrl);
|
window.location.href = response.authUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<button onClick={handleSigninWithTwitter}>Sign in with Twitter</button>
|
<div>
|
||||||
|
<button onClick={handleSignInWithTwitter}>Sign in with Twitter</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
32
pages/verification/index.tsx
Normal file
32
pages/verification/index.tsx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface AccessTokenResponse {
|
||||||
|
access_token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function VerificationPage() {
|
||||||
|
const [accessToken, setAccessToken] = useState<string>();
|
||||||
|
|
||||||
|
const fetchAccessToken = async (state: string, code: string) => {
|
||||||
|
const response: AccessTokenResponse = await (
|
||||||
|
await fetch(`/api/auth/access-token?state=${state}&code=${code}`)
|
||||||
|
).json();
|
||||||
|
|
||||||
|
setAccessToken(response.access_token);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const [, state, code] =
|
||||||
|
window.location.search.match(
|
||||||
|
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
fetchAccessToken(state, code);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>{accessToken}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user