-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Mozilla-Ocho/auth0
adding auth0
- Loading branch information
Showing
57 changed files
with
4,537 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
npm-debug.log | ||
Dockerfile | ||
.dockerignore | ||
.git | ||
.gitignore | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ node_modules | |
.vscode | ||
*.swp | ||
*.swo | ||
.env | ||
# local env files | ||
.env*.local | ||
|
||
# credentials | ||
.*.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.next/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }; | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.