-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: admin auth through kratos (#1278)
* chore: cleanup docker compose chore: update kratos * feat: user onboarding module chore: config passed on chore: saving the user chore: remove auth handler feat: e2e working login logout chore: compile * chore: remove next and pg * test: fix e2e test(e2e): helpers save fix: csr bailout and direct link fix: cypress test: with headless test? fix: probably cookies passing works test: run test save * test: huge expiration date * chore: sid comments * chore: suspense boundary * fix: flickering * fix: chekc-code * fix: use window.localstorage instead * fix: session for e2e test * fix: layout flicker * chore: move up bp * chore: jc comments * chore: auth guard
- Loading branch information
1 parent
7363247
commit 165b298
Showing
82 changed files
with
1,038 additions
and
1,520 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -43,3 +43,4 @@ results | |
build_artifacts | ||
screenshots | ||
downloads | ||
videos |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 +1,39 @@ | ||
"use client" | ||
|
||
import { CommandMenu } from "./command-menu" | ||
import CreateButton, { CreateContextProvider } from "./create" | ||
import { BreadcrumbProvider } from "./breadcrumb-provider" | ||
import { DynamicBreadcrumb } from "./dynamic-breadcrumb" | ||
|
||
import { AppSidebar } from "@/components/app-sidebar" | ||
import { RealtimePriceUpdates } from "@/components/realtime-price" | ||
import { SidebarTrigger } from "@/ui/sidebar" | ||
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/ui/sidebar" | ||
|
||
import { env } from "@/env" | ||
|
||
export const AppLayout = ({ children }: Readonly<{ children: React.ReactNode }>) => { | ||
const appVersion = env.NEXT_PUBLIC_APP_VERSION | ||
|
||
return ( | ||
<BreadcrumbProvider> | ||
<CreateContextProvider> | ||
<div className="container mx-auto p-2"> | ||
<div className="max-w-7xl w-full mx-auto"> | ||
<header className="flex justify-between items-center mb-2 align-middle"> | ||
<div className="flex items-center gap-2"> | ||
<SidebarTrigger className="md:hidden" /> | ||
<DynamicBreadcrumb /> | ||
</div> | ||
<CreateButton /> | ||
</header> | ||
<RealtimePriceUpdates /> | ||
<main>{children}</main> | ||
<CreateContextProvider> | ||
<SidebarProvider> | ||
<AppSidebar appVersion={appVersion} /> | ||
<SidebarInset className="min-h-screen md:peer-data-[variant=inset]:shadow-none border"> | ||
<CommandMenu /> | ||
<div className="container mx-auto p-2"> | ||
<div className="max-w-7xl w-full mx-auto"> | ||
<header className="flex justify-between items-center mb-2 align-middle"> | ||
<div className="flex items-center gap-2"> | ||
<SidebarTrigger className="md:hidden" /> | ||
<DynamicBreadcrumb /> | ||
</div> | ||
<CreateButton /> | ||
</header> | ||
<RealtimePriceUpdates /> | ||
<main>{children}</main> | ||
</div> | ||
</div> | ||
</div> | ||
</CreateContextProvider> | ||
</BreadcrumbProvider> | ||
</SidebarInset> | ||
</SidebarProvider> | ||
</CreateContextProvider> | ||
) | ||
} |
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,106 @@ | ||
"use client" | ||
|
||
/* eslint-disable camelcase */ // Many Ory Kratos request body params are snake_case | ||
|
||
import { Configuration, FrontendApi, UiNodeInputAttributes } from "@ory/client" | ||
import axios, { AxiosError } from "axios" | ||
|
||
import { basePath } from "@/env" | ||
|
||
export const getOryClient = () => | ||
new FrontendApi( | ||
new Configuration({ | ||
basePath, | ||
baseOptions: { | ||
withCredentials: true, | ||
timeout: 10000, | ||
}, | ||
}), | ||
"", | ||
axios, | ||
) | ||
|
||
export const getSession = () => { | ||
const kratos = getOryClient() | ||
return kratos.toSession() | ||
} | ||
|
||
export const loginUser = async (email: string) => { | ||
const oryClient = getOryClient() | ||
let flowId: string = "" | ||
|
||
try { | ||
const { data: flow } = await oryClient.createBrowserLoginFlow() | ||
flowId = flow.id | ||
|
||
const { data: loginData } = await oryClient.updateLoginFlow({ | ||
flow: flow.id, | ||
updateLoginFlowBody: { | ||
method: "code", | ||
identifier: email, | ||
csrf_token: | ||
( | ||
flow.ui.nodes.find( | ||
(node) => | ||
node.attributes.node_type === "input" && | ||
node.attributes.name === "csrf_token", | ||
)?.attributes as UiNodeInputAttributes | ||
).value || "", | ||
}, | ||
}) | ||
return loginData | ||
} catch (error) { | ||
if ( | ||
error instanceof AxiosError && | ||
error.code === AxiosError.ERR_BAD_REQUEST && | ||
error.response?.data.ui.messages[0].id === 1010014 | ||
) { | ||
return flowId | ||
} | ||
throw error | ||
} | ||
} | ||
|
||
export const loginUserWithOtp = async (flowId: string, otp: string) => { | ||
const oryClient = getOryClient() | ||
|
||
const { data: loginFlow } = await oryClient.getLoginFlow({ | ||
id: flowId, | ||
}) | ||
|
||
const csrf_token = | ||
( | ||
loginFlow.ui.nodes.find( | ||
(node) => | ||
node.attributes.node_type === "input" && node.attributes.name === "csrf_token", | ||
)?.attributes as UiNodeInputAttributes | ||
).value || "" | ||
|
||
const identifier = | ||
( | ||
loginFlow.ui.nodes.find( | ||
(node) => | ||
node.attributes.node_type === "input" && node.attributes.name === "identifier", | ||
)?.attributes as UiNodeInputAttributes | ||
).value || "" | ||
|
||
const { data: loginData } = await oryClient.updateLoginFlow({ | ||
flow: flowId, | ||
updateLoginFlowBody: { | ||
method: "code", | ||
identifier, | ||
csrf_token, | ||
code: otp, | ||
}, | ||
}) | ||
|
||
return loginData | ||
} | ||
|
||
export const logoutUser = async () => { | ||
const oryClient = getOryClient() | ||
const { data } = await oryClient.createBrowserLogoutFlow() | ||
await oryClient.updateLogoutFlow({ | ||
token: data.logout_token, | ||
}) | ||
} |
Oops, something went wrong.