mirror of
https://github.com/run-llama/newsletter-generator.git
synced 2026-06-30 22:07:56 -04:00
Fucking typescript
This commit is contained in:
Generated
+27
-1
@@ -16,10 +16,11 @@
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"typescript": "^5"
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@anthropic-ai/sdk": {
|
||||
@@ -2825,6 +2826,13 @@
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/linkify-it": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
|
||||
"integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz",
|
||||
@@ -2846,6 +2854,24 @@
|
||||
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/markdown-it": {
|
||||
"version": "14.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
|
||||
"integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/linkify-it": "^5",
|
||||
"@types/mdurl": "^2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mdurl": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
|
||||
"integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.16.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.1.tgz",
|
||||
|
||||
+4
-2
@@ -6,7 +6,8 @@
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
"lint": "next lint",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"llamaindex": "^0.5.19",
|
||||
@@ -17,9 +18,10 @@
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"typescript": "^5"
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import NextAuth from "next-auth"
|
||||
import TwitterProvider from "next-auth/providers/twitter"
|
||||
import { JWT } from "next-auth/jwt"
|
||||
|
||||
async function getTwitterUsername(accessToken) {
|
||||
async function getTwitterUsername(accessToken: string): Promise<string> {
|
||||
const response = await fetch('https://api.twitter.com/2/users/me', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
@@ -11,6 +12,10 @@ async function getTwitterUsername(accessToken) {
|
||||
return data.data.username;
|
||||
}
|
||||
|
||||
if (!process.env.TWITTER_CLIENT_ID || !process.env.TWITTER_CLIENT_SECRET) {
|
||||
throw new Error('Missing Twitter OAuth credentials');
|
||||
}
|
||||
|
||||
export const authOptions = {
|
||||
providers: [
|
||||
TwitterProvider({
|
||||
@@ -20,7 +25,7 @@ export const authOptions = {
|
||||
})
|
||||
],
|
||||
callbacks: {
|
||||
async signIn({ user, account }) {
|
||||
async signIn({ user, account }: { user: any; account: any }) {
|
||||
const username = await getTwitterUsername(account.access_token);
|
||||
// Check if the user's Twitter username matches the allowed username
|
||||
if (username === process.env.TWITTER_USER) {
|
||||
@@ -29,14 +34,14 @@ export const authOptions = {
|
||||
return false; // Deny sign in
|
||||
}
|
||||
},
|
||||
async jwt({ token, account }) {
|
||||
async jwt({ token, account }: { token: JWT; account: any }) {
|
||||
// Persist the OAuth access_token to the token right after signin
|
||||
if (account) {
|
||||
token.accessToken = account.access_token
|
||||
}
|
||||
return token
|
||||
},
|
||||
async session({ session, token }) {
|
||||
async session({ session, token}: { session: any; token: JWT }) {
|
||||
// Send properties to the client, like an access_token from a provider.
|
||||
session.accessToken = token.accessToken
|
||||
return session
|
||||
+2
-2
@@ -7,7 +7,7 @@ const md = markdownit();
|
||||
|
||||
function LoginStatus() {
|
||||
const { data: session } = useSession();
|
||||
if (session) {
|
||||
if (session && session.user) {
|
||||
return (
|
||||
<div className="login-status">
|
||||
Signed in as {session.user.name} <br />
|
||||
@@ -60,7 +60,7 @@ export default function Home() {
|
||||
<main className="main">
|
||||
<h1>Newsletter Generator</h1>
|
||||
<LoginStatus />
|
||||
{session?.user.name && (
|
||||
{session && session.user && session.user.name && (
|
||||
<div>
|
||||
<button onClick={handleClick} disabled={isStreaming}>
|
||||
{isStreaming ? 'Streaming...' : 'Generate newsletter'}
|
||||
|
||||
+1
-1
@@ -22,5 +22,5 @@
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"exclude": ["node_modules",".next"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user