Skip to content

Commit

Permalink
update account table to add oauth_token, oauth_token_secret.
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemistgo87 authored and kespinola committed Jul 17, 2023
1 parent 4263cf5 commit 1579643
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"http-proxy": "^1.18.1",
"install": "^0.13.0",
"micro": "^10.0.1",
"next": "^13.4.9",
"next-auth": "^4.19.2",
"next": "^13.3.1",
"next-auth": "^4.22.1",
"next-plugin-graphql": "^0.0.2",
"npm": "^9.6.1",
"prisma": "^4.9.0",
Expand Down
3 changes: 3 additions & 0 deletions prisma/migrations/20230713130227_twitter_oauth/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Account" ADD COLUMN "oauth_token" TEXT,
ADD COLUMN "oauth_token_secret" TEXT;
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ model Account {
scope String?
id_token String? @db.Text
session_state String?
oauth_token String? @db.Text
oauth_token_secret String? @db.Text
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand Down
1 change: 1 addition & 0 deletions src/app/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface HomeProps {

export default function Home({ session }: HomeProps) {
const me = useMe();
console.log('me in home', me);
const dropQuery = useQuery(GetDrop);
const collection = dropQuery.data?.drop.collection;
const metadataJson = collection?.metadataJson;
Expand Down
12 changes: 6 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Drop as DropType, Project } from "@/graphql.types";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import Home from "./Home";
import { Drop as DropType, Project } from '@/graphql.types';
import { getServerSession } from 'next-auth/next';
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import Home from './Home';

interface GetDropVars {
project: string;
drop: string;
}

interface GetDropData {
project: Pick<Project, "drop">;
project: Pick<Project, 'drop'>;
}

export default async function HomePage() {
const session = await getServerSession(authOptions);

console.log('session', session);
return <Home session={session} />;
}
20 changes: 10 additions & 10 deletions src/modules/user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
import { PrismaClient } from "@prisma/client";
import { Project, AssetType, User } from "@/graphql.types";
import { GetCustomerWallet } from "@/queries/customer.graphql";
import { ApolloClient, NormalizedCacheObject } from '@apollo/client';
import { PrismaClient } from '@prisma/client';
import { Project, AssetType, User } from '@/graphql.types';
import { GetCustomerWallet } from '@/queries/customer.graphql';

interface GetCustomerWalletData {
project: Pick<Project, "customer">;
project: Pick<Project, 'customer'>;
}

interface GetCustomerWalletVars {
Expand All @@ -28,27 +28,27 @@ export default class UserSource {
}

const user = await this.db.user.findFirst({
where: { email },
where: { email }
});

const { data } = await this.holaplex.query<
GetCustomerWalletData,
GetCustomerWalletVars
>({
fetchPolicy: "network-only",
fetchPolicy: 'network-only',
query: GetCustomerWallet,
variables: {
project: process.env.HOLAPLEX_PROJECT_ID as string,
customer: user?.holaplexCustomerId as string,
assetType: process.env.HOLAPLEX_WALLET_ASSET_TYPE as AssetType,
},
assetType: process.env.HOLAPLEX_WALLET_ASSET_TYPE as AssetType
}
});

return {
name: user?.name,
email: user?.email,
image: user?.image,
wallet: data.project.customer?.treasury?.wallet,
wallet: data.project.customer?.treasury?.wallet
} as User;
}
}
10 changes: 9 additions & 1 deletion src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const authOptions: NextAuthOptions = {
TwitterProvider({
clientId: process.env.TWITTER_CLIENT_ID as string,
clientSecret: process.env.TWITTER_CLIENT_SECRET as string
//version: '2.0' // opt-in to Twitter OAuth 2.0
})
],
events: {
Expand All @@ -94,6 +95,7 @@ export const authOptions: NextAuthOptions = {
}
});

console.log('customer data', createCustomerResponse.data);
const customer = createCustomerResponse.data?.createCustomer.customer;

const me = await db.user.update({
Expand All @@ -105,6 +107,8 @@ export const authOptions: NextAuthOptions = {
}
});

console.log('me', me);

await waitUntil(customerTreasuryReady(customer?.id as string), {
intervalBetweenAttempts: 100
});
Expand All @@ -122,15 +126,19 @@ export const authOptions: NextAuthOptions = {
}
});

console.log('customer wallet', createCustomerWalletResponse);

const wallet =
createCustomerWalletResponse.data?.createCustomerWallet.wallet;

await db.wallet.create({
const savedWallet = await db.wallet.create({
data: {
holaplexCustomerId: me.holaplexCustomerId as string,
address: wallet?.address as string
}
});

console.log('saved wallet', savedWallet);
}
}
};
Expand Down

0 comments on commit 1579643

Please sign in to comment.