Skip to content

Commit

Permalink
chore: poc on replacing the hydra demo app to a real dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Oct 2, 2023
1 parent 7f5ef9d commit 8155d2e
Show file tree
Hide file tree
Showing 25 changed files with 3,816 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"es6": true,
"node": true
},
"ignorePatterns": ["/*.js", "lib", "coverage", "generated", "protos"],
"ignorePatterns": ["/*.js", "lib", "coverage", "generated", "protos", "apps"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
Expand Down
10 changes: 7 additions & 3 deletions apps/consent/src/routes/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ router.get("/", csrfProtection, async (req, res, next) => {
// unless you limit who can introspect tokens.
access_token: { card: "alice" },
// This data will be available in the ID token.
id_token: { who: "bob" },

// TODO fetch email
id_token: { who: "bob", email: "" },
},
},
})
Expand Down Expand Up @@ -127,9 +129,11 @@ router.post("/", csrfProtection, async (req, res, next) => {
let session = {
// This data will be available when introspecting the token. Try to avoid sensitive information here,
// unless you limit who can introspect tokens.
access_token: { card: "alice" },

// TODO: pass email
access_token: { card: "alice", email: "" },
// This data will be available in the ID token.
id_token: { card: "bob" },
id_token: { card: "bob", email: "" },
}

try {
Expand Down
17 changes: 13 additions & 4 deletions apps/consent/src/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,21 @@ router.post("/", csrfProtection, async (req, res, next) => {

const url = `${authUrl}/auth/email/code`

const result = await axios.post(url, {
email,
})
let emailLoginId: string

try {
const result = await axios.post(url, {
email,
})
emailLoginId = result.data.result
} catch (err) {
// TODO: error layout
console.error(err)
return
}

// TODO: manage error on ip rate limit
// TODO: manage error when trying the same email too often
const emailLoginId = result.data.result

if (emailLoginId) {
console.log({ emailLoginId })
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXTAUTH_URL=https://bdb1-93-108-186-220.ngrok-free.app
PORT=3001
NEXTAUTH_SECRET="thisismysecret"
3 changes: 3 additions & 0 deletions apps/dashboard/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
35 changes: 35 additions & 0 deletions apps/dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions apps/dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
55 changes: 55 additions & 0 deletions apps/dashboard/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import NextAuth from "next-auth"
import GithubProvider from "next-auth/providers/auth0"
import { ProviderType } from "next-auth/providers/index"

const type = "oauth" as const // as ProviderType

export const authOptions = {
// Configure one or more authentication providers
providers: [
{
id: "blink",
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
wellKnown: "http://127.0.0.1:4444/.well-known/openid-configuration",
useSecureCookies: false,
authorization: { params: { scope: "offline transactions:read" } },
idToken: false,
name: "Blink",
type,
profile(profile) {
console.log({ profile }, "profile123")
return {
id: profile.sub,
// email: profile.email,
}
},
},
// ...add more providers here
],
debug: true,
secret: process.env.NEXTAUTH_SECRET as string,
callbacks: {
async jwt({ token, account, profile }) {
// Persist the OAuth access_token and or the user id to the token right after signin
if (account) {
token.accessToken = account.access_token
token.expiresAt = account.expires_at
token.refreshToken = account.refresh_token
token.id = profile.id
}
return token
},
async session({ session, token, user }) {
console.log({ session, token, user }, "session12")
// Send properties to the client, like an access_token from a provider.
session.sub = token.sub
session.accessToken = token.accessToken
return session
},
},
}

const handler = NextAuth(authOptions)

export { handler as GET, handler as POST }
Binary file added apps/dashboard/app/favicon.ico
Binary file not shown.
27 changes: 27 additions & 0 deletions apps/dashboard/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
4 changes: 4 additions & 0 deletions apps/dashboard/app/graphql/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// export const serverUrl =
// process.env.SERVER_URL ?? "https://fe69-93-108-186-220.ngrok-free.app"

export const coreUrl = process.env.CORE_URL ?? "http://localhost:4002/graphql"
Loading

0 comments on commit 8155d2e

Please sign in to comment.