-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: package.json | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm run check-format | ||
- run: npm run build | ||
- run: npm run test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "run-p dev:*", | ||
"dev:admin": "npm run dev --workspace=admin", | ||
"dev:client": "npm run dev --workspace=client", | ||
"dev:server": "npm run dev --workspace=server", | ||
"lint": "eslint --ext .ts,.tsx .", | ||
"check-format": "prettier --check .", | ||
"format": "prettier --write .", | ||
"build": "npm run build --workspaces", | ||
"test": "npm run test --workspaces --if-present" | ||
}, | ||
"workspaces": [ | ||
"projects/server", | ||
"projects/admin", | ||
"projects/client", | ||
"projects/admin" | ||
"projects/server" | ||
], | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.17.0", | ||
"@typescript-eslint/parser": "^6.17.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^3.1.1", | ||
"typescript": "~5.3.3" | ||
}, | ||
"engines": { | ||
"node": "^20.10.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { z } from "zod"; | ||
import type { AuthProvider } from "react-admin"; | ||
import { trpc } from "./trpc"; | ||
import { TRPCClientError } from "@trpc/client"; | ||
|
||
const loginParamsSchema = z.object({ | ||
email: z.string().email(), | ||
}); | ||
|
||
const trpcErrorSchema = z.object({ | ||
code: z.string(), | ||
httpStatus: z.number().int(), | ||
path: z.string(), | ||
}); | ||
|
||
export const authProvider: AuthProvider = { | ||
login: async (params) => { | ||
const { email } = loginParamsSchema.parse(params); | ||
const callbackUrl = new URL(window.location.origin); | ||
callbackUrl.hash = "/auth-callback"; | ||
await trpc.authentication.initialize.mutate({ | ||
Check failure on line 21 in projects/admin/src/auth-provider.ts GitHub Actions / test
|
||
email, | ||
callbackUrl: callbackUrl.href, | ||
}); | ||
}, | ||
|
||
handleCallback: async () => { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
window.location.search = ""; | ||
|
||
const token = searchParams.get("token"); | ||
if (!token) { | ||
return; | ||
} | ||
|
||
await trpc.authentication.verifyToken.mutate({ token }); | ||
Check failure on line 36 in projects/admin/src/auth-provider.ts GitHub Actions / test
|
||
}, | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
checkError: async (error) => { | ||
if (!(error instanceof TRPCClientError)) { | ||
return; | ||
} | ||
const errorData = trpcErrorSchema.parse(error.data); | ||
if (errorData.code === "UNAUTHORIZED") { | ||
throw new Error("not signed in"); | ||
} | ||
return; | ||
}, | ||
|
||
checkAuth: async () => { | ||
const signedIn = await trpc.validateSession.query(); | ||
Check failure on line 52 in projects/admin/src/auth-provider.ts GitHub Actions / test
Check failure on line 52 in projects/admin/src/auth-provider.ts GitHub Actions / test
|
||
if (!signedIn) { | ||
throw new Error("not signed in"); | ||
} | ||
}, | ||
|
||
logout: async () => { | ||
try { | ||
await trpc.authentication.signOut.mutate(); | ||
Check failure on line 60 in projects/admin/src/auth-provider.ts GitHub Actions / test
|
||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, | ||
|
||
getPermissions: () => { | ||
return Promise.resolve("admin"); | ||
}, | ||
}; |