Skip to content

Commit 983089a

Browse files
Adjust config and JWT endpoint for 55 (#20)
Co-authored-by: Timofei Kachalov <[email protected]>
1 parent 797a883 commit 983089a

File tree

12 files changed

+99
-98
lines changed

12 files changed

+99
-98
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
3232
METABASE_INSTANCE_URL: "http://metabase:${MB_PORT}"
3333
METABASE_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}"
34-
WATCH: '${WATCH}'
34+
WATCH: "${WATCH}"
3535
environment:
3636
PORT: "${CLIENT_PORT_APP_ROUTER}"
3737
NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
@@ -54,7 +54,7 @@ services:
5454
NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
5555
METABASE_INSTANCE_URL: "http://metabase:${MB_PORT}"
5656
METABASE_JWT_SHARED_SECRET: "${METABASE_JWT_SHARED_SECRET}"
57-
WATCH: '${WATCH}'
57+
WATCH: "${WATCH}"
5858
environment:
5959
PORT: "${CLIENT_PORT_PAGES_ROUTER}"
6060
NEXT_PUBLIC_METABASE_INSTANCE_URL: "http://localhost:${MB_PORT}"
@@ -63,4 +63,4 @@ services:
6363
ports:
6464
- "${CLIENT_PORT_PAGES_ROUTER}:${CLIENT_PORT_PAGES_ROUTER}"
6565
volumes:
66-
- ./next-sample-pages-router/src:/app/next-sample-pages-router/src
66+
- ./next-sample-pages-router/src:/app/next-sample-pages-router/src

metabase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM metabase/metabase-enterprise:v1.54.x
1+
FROM metabase/metabase-enterprise:v1.55.x
22

33
COPY ./metabase /app/
44
COPY ./local-dist /app/local-dist

next-sample-app-router/package-lock.json

Lines changed: 18 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

next-sample-app-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@metabase/embedding-sdk-react": "^0.54.11",
12+
"@metabase/embedding-sdk-react": "^0.55.2-nightly",
1313
"dotenv-cli": "^8.0.0",
1414
"jsonwebtoken": "^9.0.2",
1515
"next": "14.2.18",

next-sample-app-router/src/app/api/metabase/auth/route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import jwt from "jsonwebtoken";
2+
import { NextResponse } from 'next/server';
23

34
if (!process.env.METABASE_JWT_SHARED_SECRET) {
45
throw new Error("Missing METABASE_JWT_SHARED_SECRET");
@@ -10,7 +11,7 @@ if (!process.env.NEXT_PUBLIC_METABASE_INSTANCE_URL) {
1011
const METABASE_JWT_SHARED_SECRET = process.env.METABASE_JWT_SHARED_SECRET;
1112
const METABASE_INSTANCE_URL = process.env.METABASE_INSTANCE_URL;
1213

13-
export async function GET() {
14+
export async function GET(req: Request) {
1415
// this should come from the session
1516
const user = {
1617
@@ -30,7 +31,14 @@ export async function GET() {
3031
METABASE_JWT_SHARED_SECRET
3132
);
3233

33-
const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?token=true&jwt=${token}`;
34+
const url = new URL(req.url)
35+
const wantsJson = url.searchParams.get('response') === 'json'
36+
37+
if (wantsJson) {
38+
return NextResponse.json({ jwt: token })
39+
}
40+
41+
const ssoUrl = `${METABASE_INSTANCE_URL}/auth/sso?jwt=${token}`;
3442

3543
try {
3644
const response = await fetch(ssoUrl);

next-sample-app-router/src/app/app-provider.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
import {
44
MetabaseProvider,
55
defineMetabaseAuthConfig,
6-
defineMetabaseTheme
7-
} from '@metabase/embedding-sdk-react/nextjs';
8-
import { PropsWithChildren } from 'react';
6+
defineMetabaseTheme,
7+
} from "@metabase/embedding-sdk-react/nextjs";
8+
import { PropsWithChildren } from "react";
99

1010
if (!process.env.NEXT_PUBLIC_METABASE_INSTANCE_URL) {
1111
throw new Error("Missing NEXT_PUBLIC_METABASE_INSTANCE_URL");
1212
}
1313

1414
const authConfig = defineMetabaseAuthConfig({
1515
metabaseInstanceUrl: process.env.NEXT_PUBLIC_METABASE_INSTANCE_URL,
16-
authProviderUri: `/api/metabase/auth`,
16+
fetchRequestToken: async () => {
17+
const response = await fetch('/api/metabase/auth?response=json', {
18+
method: "GET",
19+
credentials: "include",
20+
});
21+
22+
return await response.json();
23+
},
1724
});
1825

1926
const theme = defineMetabaseTheme({
@@ -57,11 +64,8 @@ const theme = defineMetabaseTheme({
5764
},
5865
});
5966

60-
export const AppProvider = ({children}: PropsWithChildren) => (
61-
<MetabaseProvider
62-
authConfig={authConfig}
63-
theme={theme}
64-
>
67+
export const AppProvider = ({ children }: PropsWithChildren) => (
68+
<MetabaseProvider authConfig={authConfig} theme={theme}>
6569
{children}
6670
</MetabaseProvider>
67-
)
71+
);

next-sample-app-router/src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { Metadata } from "next";
33
import localFont from "next/font/local";
44
import "./globals.css";
55
import Link from "next/link";
6-
import { AppProvider } from '@/app/app-provider';
7-
import { Suspense } from 'react';
6+
import { AppProvider } from "@/app/app-provider";
7+
import { Suspense } from "react";
88

99
const geistSans = localFont({
1010
src: "./fonts/GeistVF.woff",

next-sample-pages-router/package-lock.json

Lines changed: 18 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

next-sample-pages-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@metabase/embedding-sdk-react": "^0.54.11",
12+
"@metabase/embedding-sdk-react": "^0.55.2-nightly",
1313
"dotenv-cli": "^8.0.0",
1414
"jsonwebtoken": "^9.0.2",
1515
"next": "14.2.18",

next-sample-pages-router/src/components/app-provider.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ if (!process.env.NEXT_PUBLIC_METABASE_INSTANCE_URL) {
1111

1212
const authConfig = defineMetabaseAuthConfig({
1313
metabaseInstanceUrl: process.env.NEXT_PUBLIC_METABASE_INSTANCE_URL,
14-
authProviderUri: `/api/metabase/auth`,
14+
fetchRequestToken: async () => {
15+
const response = await fetch('/api/metabase/auth?response=json', {
16+
method: "GET",
17+
credentials: "include",
18+
});
19+
20+
return await response.json();
21+
},
1522
});
1623

1724
const theme = defineMetabaseTheme({

0 commit comments

Comments
 (0)