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

adding auth0 #7

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
.env
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ node_modules
.vscode
*.swp
*.swo
.env
# local env files
.env*.local

# credentials
.*.json
Expand Down
74 changes: 52 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
# Innovation Studio boilerplate app template

This boilerplate repo is still under heavy initial development. We are
exercising the process of rapidly spinning up a reproducible application stack,
see doc/system-archictecture.png for the current architecture.

Goals:
- Minimize technical effort that isn't germane to the ideas we want to test
- Select and develop tools we like as a team and commit to reusing them
- All pods benefit from other pod contributions to the boilerplate
- Re-use effort and learnings from Graceland’s stack
- Quick to spin up for simple demos/prototypes
- Encourage sharing dev effort and cross-contribution across pods with
normalized conventions
- Serve also as a solid foundation for production MVPs and eventual GA releases
- Moco-friendly stack: GCP-based, built on best practices with generic
primitives, not reliant on third parties (e.g. heroku)
- Flexible, minimal, modular architecture that can replace or include new
components as needed (alternate backends, cloud functions, A/B testing,
CDNs, etc)
- Innovation Studio is the first customer, but this might provide value in Moz
more broadly and/or as open source project.
# PROTO

This is a prototype repo for team Bosque (name can potentially change).

## Getting started

```bash
docker compose up --build
```

or if already built

```bash
docker compose up
```

## Getting latest database changes

```bash
docker compose exec -it appserver yarn knex migrate:latest
```

## Installing new packages

```bash
docker compose exec -it appserver yarn install
```


## ENV Vars

Auth0: Creating scafolding but not in use

```bash
AUTH0_SECRET=
AUTH0_CLIENT_ID=
AUTH0_ISSUER_BASE_URL=
AUTH0_CLIENT_SECRET=
AUTH0_BASE_URL='http://localhost:3000'
```

Github: Not currently in use

```bash
GITHUB_TOKEN=
```

OpenAI: Needed to for any AI interaciton

```bash
OPENAI_API_KEY=
ASSISTANT_ID=
```
1 change: 1 addition & 0 deletions appserver/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.next/
84 changes: 84 additions & 0 deletions appserver/app/api/auth/[auth0]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// import { UserService } from "@/services/UserService";

import {
handleAuth,
handleCallback,
handleLogin,
Session,
updateSession,
} from "@auth0/nextjs-auth0";
import { NextRequest } from "next/server";

// const afterCallback = async (
// req: NextRequest,
// session: Session
// ): Promise<Session> => {
// if (!session) {
// throw new Error("Unable to authenticate user");
// }

// const { user } = session;
// const { sub, email_verified, email } = user;
// const storedUser = await UserService.getByAccountProviderId(sub);

// if (storedUser) {
// const newSession = {
// ...session,
// user: { ...user, id: storedUser.id, username: storedUser.username },
// };

// await updateSession(newSession);
// return newSession;
// //create user record
// }

// const providerData = {
// id_token: session.idToken,
// refresh_token: session.refreshToken,
// access_token: session.accessToken,
// access_token_expires: session.accessTokenExpiresAt,
// provider: "auth0",
// provider_account_id: user.sub,
// };

// const newUser = await UserService.create(
// {
// email_verified,
// email,
// },
// providerData
// );

// if (newUser) {
// const newSession = {
// ...session,
// user: { ...user, id: newUser.id, username: newUser.username },
// };
// await updateSession(newSession);
// return newSession;
// }
// throw new Error("Unable to authenticate user");
// };

export const GET = handleAuth({
login: handleLogin((req) => {
return {
returnTo: "/",
};
}),
signup: handleLogin({
authorizationParams: {
screen_hint: "signup",
},
returnTo: "/profile",
}),
signIn: handleLogin({
authorizationParams: {
screen_hint: "signin",
},
returnTo: "/profile",
}),
callback: handleCallback((req) => {
return { redirectUri: "http://localhost:3000" };
}),
});
17 changes: 17 additions & 0 deletions appserver/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { openai } from '@ai-sdk/openai'
import { convertToCoreMessages, streamText } from 'ai'

// Allow streaming responses up to 30 seconds
export const maxDuration = 30

export async function POST(req: Request) {
const { messages } = await req.json()

const result = await streamText({
model: openai('gpt-4o'),
system: 'You are a helpful assistant.',
messages: convertToCoreMessages(messages),
})

return result.toDataStreamResponse()
}
58 changes: 58 additions & 0 deletions appserver/app/api/github/[actions]/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { NextApiRequest, NextApiResponse } from 'next'
import GithubService from '@Services/server/github.service'

const githubService = new GithubService(process.env.GITHUB_TOKEN || '')

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { action, owner, repo, path } = req.query

try {
let data
switch (action) {
case 'getRepo':
data = await githubService.getRepo(owner as string, repo as string)
break
case 'getContributors':
data = await githubService.getContributors(
owner as string,
repo as string
)
break
case 'getIssues':
data = await githubService.getIssues(owner as string, repo as string)
break
case 'getPullRequests':
data = await githubService.getPullRequests(
owner as string,
repo as string
)
break
case 'getBranches':
data = await githubService.getBranches(owner as string, repo as string)
break
case 'getTags':
data = await githubService.getTags(owner as string, repo as string)
break
case 'getContents':
data = await githubService.getContents(
owner as string,
repo as string,
path as string
)
break
case 'getCommits':
data = await githubService.getCommits(owner as string, repo as string)
break
default:
return res.status(400).json({ message: 'Invalid action' })
}

res.status(200).json(data)
} catch (error) {
console.error(error)
res.status(500).json({ message: 'there was an error see logs' })
}
}
7 changes: 7 additions & 0 deletions appserver/app/dashboard/code/page.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use 'styles/core/boilerplate' as *;

.contributor {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 20px;
}
92 changes: 92 additions & 0 deletions appserver/app/dashboard/code/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import GithubService from '@Services/server/github.service'
import styles from './page.module.scss'
import Markdown from 'react-markdown'

export default async function Page() {
const githubService = new GithubService(process.env.GITHUB_TOKEN || '')

const repo = await githubService.getRepo('Facebook', 'React')
const contributors = await githubService.getContributors('Facebook', 'React')
const issues = await githubService.getIssues('Facebook', 'React')
const content = await githubService.getContents(
'Facebook',
'React',
'README.md'
)
console.log('content', content)
console.log(
'buffer content',
Buffer.from(content.content, 'base64').toString('utf-8')
)

return (
<div className="page_wrapper">
<h1 className="heading-lg">Code Base</h1>
<div className="card">
<h3 className="heading-xs mb-24">File content test</h3>
<div className="markdown">
<Markdown>
{Buffer.from(content.content, 'base64').toString('utf-8')}
</Markdown>
</div>
</div>
<div className="flex gap-12">
<div className="card">
<h3 className="heading-xs mb-24">Repo Details</h3>
<div className="flex-col gap-12 ">
<p>
<strong>Owner:</strong> {repo.owner.login}
</p>
<p>
<strong>Private:</strong> {repo.private ? 'Yes' : 'No'}
</p>
<p>
<strong>Default Branch:</strong> {repo.default_branch}
</p>
<p>
<strong>Language:</strong> {repo.language}
</p>
<p>
<strong>Size:</strong> {repo.size}
</p>
</div>
</div>
<div className="card grow">
<h3 className="heading-xs mb-24">Top Contributors</h3>
<div className={styles.contributor}>
{contributors.map((contributor) => (
<div key={contributor.id}>
<p>
<strong>Login:</strong> {contributor.login}
</p>
<p>
<strong>Contributions:</strong> {contributor.contributions}
</p>
</div>
))}
</div>
</div>
</div>
<div>
<div className="card">
<h3 className="heading-xs mb-24">Repo Issues</h3>
<div className="flex-col gap-12 font-14">
{issues.map((issue) => (
<div key={issue.id}>
<p>
<strong>Title:</strong> {issue.title}
</p>
<p>
<strong>State:</strong> {issue.state}
</p>
<p>
<strong>Comments:</strong> {issue.comments}
</p>
</div>
))}
</div>
</div>
</div>
</div>
)
}
6 changes: 6 additions & 0 deletions appserver/app/dashboard/layout.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@use 'styles/core/boilerplate' as *;

.wrapper {
display: grid;
grid-template-columns: 300px 1fr;
}
12 changes: 12 additions & 0 deletions appserver/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ReactNode } from 'react'
import SideNav from '@Navigation/SideNav/SideNav'
import styles from './layout.module.scss'

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<div className={styles.wrapper}>
<SideNav />
{children}
</div>
)
}
3 changes: 3 additions & 0 deletions appserver/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default async function Page() {
return <div className="py-12">im the main page content</div>
}
7 changes: 7 additions & 0 deletions appserver/app/dashboard/sandbox/page.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use 'styles/core/boilerplate' as *;

.contributor {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 20px;
}
Loading