-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d48c76e
commit e3eb40d
Showing
13 changed files
with
265 additions
and
172 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
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
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
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,49 @@ | ||
import "./index.css"; | ||
import type { Client } from "@osdk/client"; | ||
import { createClient } from "@osdk/client"; | ||
import { $ontologyRid } from "@osdk/e2e.generated.catchall"; | ||
import { createPublicOauthClient } from "@osdk/oauth"; | ||
|
||
function checkEnv( | ||
value: string | undefined, | ||
name: string, | ||
): asserts value is string { | ||
if (value == null) { | ||
throw new Error(`Missing environment variable: ${name}`); | ||
} | ||
} | ||
|
||
export default function createClientAndAuth() { | ||
const url = import.meta.env.VITE_FOUNDRY_API_URL; | ||
const clientId = import.meta.env.VITE_FOUNDRY_CLIENT_ID; | ||
const redirectUrl = import.meta.env.VITE_FOUNDRY_REDIRECT_URL; | ||
const scopes = [ | ||
"api:ontologies-read", | ||
"api:ontologies-write", | ||
]; | ||
|
||
checkEnv(url, "VITE_FOUNDRY_API_URL"); | ||
checkEnv(clientId, "VITE_FOUNDRY_CLIENT_ID"); | ||
checkEnv(redirectUrl, "VITE_FOUNDRY_REDIRECT_URL"); | ||
|
||
const auth = createPublicOauthClient( | ||
clientId, | ||
url, | ||
redirectUrl, | ||
true, | ||
undefined, | ||
window.location.toString(), | ||
scopes, | ||
); | ||
|
||
/** | ||
* Initialize the client to interact with the Ontology SDK | ||
*/ | ||
const client: Client = createClient( | ||
url, | ||
$ontologyRid, | ||
auth, | ||
); | ||
|
||
return { client, auth } | ||
} |
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,24 +1,14 @@ | ||
import { OsdkProvider } from "@osdk/react"; | ||
import ReactDOM from "react-dom/client"; | ||
import { createBrowserRouter, RouterProvider } from "react-router-dom"; | ||
import AuthCallback from "./AuthCallback"; | ||
import Home from "./Home"; | ||
import { RouterProvider } from "react-router-dom"; | ||
import createClientAndAuth from "./createClientAndAuth"; | ||
import "./index.css"; | ||
import { router } from "./router"; | ||
|
||
const router = createBrowserRouter( | ||
[ | ||
{ | ||
path: "/", | ||
element: <Home />, | ||
}, | ||
{ | ||
// This is the route defined in your application's redirect URL | ||
path: "/auth/callback", | ||
element: <AuthCallback />, | ||
}, | ||
], | ||
{ basename: import.meta.env.BASE_URL }, | ||
); | ||
const { client } = createClientAndAuth(); | ||
|
||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<RouterProvider router={router} />, | ||
<OsdkProvider client={client}> | ||
<RouterProvider router={router} />, | ||
</OsdkProvider>, | ||
); |
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,18 @@ | ||
import { createBrowserRouter } from "react-router-dom"; | ||
import AuthCallback from "./AuthCallback"; | ||
import Home from "./Home"; | ||
|
||
export const router = createBrowserRouter( | ||
[ | ||
{ | ||
path: "/", | ||
element: <Home />, | ||
}, | ||
{ | ||
// This is the route defined in your application's redirect URL | ||
path: "/auth/callback", | ||
element: <AuthCallback />, | ||
}, | ||
], | ||
{ basename: import.meta.env.BASE_URL }, | ||
); |
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
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
54 changes: 54 additions & 0 deletions
54
packages/create-app.template.react.beta/templates/src/createClientAndAuth.ts.hbs
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,54 @@ | ||
import "./index.css"; | ||
import type { Client } from "@osdk/client"; | ||
import { createClient } from "@osdk/client"; | ||
import { $ontologyRid } from "@osdk/e2e.generated.catchall"; | ||
import { createPublicOauthClient } from "@osdk/oauth"; | ||
|
||
function checkEnv( | ||
value: string | undefined, | ||
name: string, | ||
): asserts value is string { | ||
if (value == null) { | ||
throw new Error(`Missing environment variable: ${name}`); | ||
} | ||
} | ||
|
||
export default function createClientAndAuth() { | ||
const url = import.meta.env.VITE_FOUNDRY_API_URL; | ||
const clientId = import.meta.env.VITE_FOUNDRY_CLIENT_ID; | ||
const redirectUrl = import.meta.env.VITE_FOUNDRY_REDIRECT_URL; | ||
{{#if scopes}} | ||
const scopes = [ | ||
{{#each scopes}} | ||
"{{this}}", | ||
{{/each}} | ||
]; | ||
{{/if}} | ||
|
||
checkEnv(url, "VITE_FOUNDRY_API_URL"); | ||
checkEnv(clientId, "VITE_FOUNDRY_CLIENT_ID"); | ||
checkEnv(redirectUrl, "VITE_FOUNDRY_REDIRECT_URL"); | ||
|
||
const auth = createPublicOauthClient( | ||
clientId, | ||
url, | ||
redirectUrl, | ||
{{#if scopes}} | ||
true, | ||
undefined, | ||
window.location.toString(), | ||
scopes, | ||
{{/if}} | ||
); | ||
|
||
/** | ||
* Initialize the client to interact with the Ontology SDK | ||
*/ | ||
const client: Client = createClient( | ||
url, | ||
$ontologyRid, | ||
auth, | ||
); | ||
|
||
return { client, auth } | ||
} |
26 changes: 8 additions & 18 deletions
26
packages/create-app.template.react.beta/templates/src/main.tsx
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,24 +1,14 @@ | ||
import { OsdkProvider } from "@osdk/react"; | ||
import ReactDOM from "react-dom/client"; | ||
import { createBrowserRouter, RouterProvider } from "react-router-dom"; | ||
import AuthCallback from "./AuthCallback"; | ||
import Home from "./Home"; | ||
import { RouterProvider } from "react-router-dom"; | ||
import createClientAndAuth from "./createClientAndAuth"; | ||
import "./index.css"; | ||
import { router } from "./router"; | ||
|
||
const router = createBrowserRouter( | ||
[ | ||
{ | ||
path: "/", | ||
element: <Home />, | ||
}, | ||
{ | ||
// This is the route defined in your application's redirect URL | ||
path: "/auth/callback", | ||
element: <AuthCallback />, | ||
}, | ||
], | ||
{ basename: import.meta.env.BASE_URL }, | ||
); | ||
const { client } = createClientAndAuth(); | ||
|
||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<RouterProvider router={router} />, | ||
<OsdkProvider client={client}> | ||
<RouterProvider router={router} />, | ||
</OsdkProvider>, | ||
); |
18 changes: 18 additions & 0 deletions
18
packages/create-app.template.react.beta/templates/src/router.tsx
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,18 @@ | ||
import { createBrowserRouter } from "react-router-dom"; | ||
import AuthCallback from "./AuthCallback"; | ||
import Home from "./Home"; | ||
|
||
export const router = createBrowserRouter( | ||
[ | ||
{ | ||
path: "/", | ||
element: <Home />, | ||
}, | ||
{ | ||
// This is the route defined in your application's redirect URL | ||
path: "/auth/callback", | ||
element: <AuthCallback />, | ||
}, | ||
], | ||
{ basename: import.meta.env.BASE_URL }, | ||
); |
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
Oops, something went wrong.