@wasp.sh/wasp-cli-darwin-arm64-unknown 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @wasp.sh/wasp-cli-darwin-arm64-unknown might be problematic. Click here for more details.
- package/data/Cli/bash-completion +5 -0
- package/data/Cli/starters/README.md +22 -0
- package/data/Cli/starters/basic/.prettierignore +2 -0
- package/data/Cli/starters/basic/.prettierrc +3 -0
- package/data/Cli/starters/basic/README.md +35 -0
- package/data/Cli/starters/basic/eslint.config.js +15 -0
- package/data/Cli/starters/basic/main.wasp +100 -0
- package/data/Cli/starters/basic/package.json +27 -0
- package/data/Cli/starters/basic/postcss.config.cjs +6 -0
- package/data/Cli/starters/basic/schema.prisma +42 -0
- package/data/Cli/starters/basic/src/App.css +13 -0
- package/data/Cli/starters/basic/src/App.tsx +12 -0
- package/data/Cli/starters/basic/src/assets/logo.svg +1 -0
- package/data/Cli/starters/basic/src/auth/AuthLayout.tsx +10 -0
- package/data/Cli/starters/basic/src/auth/email/EmailVerificationPage.tsx +19 -0
- package/data/Cli/starters/basic/src/auth/email/LoginPage.tsx +27 -0
- package/data/Cli/starters/basic/src/auth/email/PasswordResetPage.tsx +19 -0
- package/data/Cli/starters/basic/src/auth/email/RequestPasswordResetPage.tsx +10 -0
- package/data/Cli/starters/basic/src/auth/email/SignupPage.tsx +34 -0
- package/data/Cli/starters/basic/src/auth/email/userSignupFields.ts +13 -0
- package/data/Cli/starters/basic/src/shared/components/Button.tsx +90 -0
- package/data/Cli/starters/basic/src/shared/components/Dialog.tsx +85 -0
- package/data/Cli/starters/basic/src/shared/components/Header.tsx +39 -0
- package/data/Cli/starters/basic/src/shared/components/Input.tsx +36 -0
- package/data/Cli/starters/basic/src/shared/components/Portal.tsx +26 -0
- package/data/Cli/starters/basic/src/tags/actions.ts +23 -0
- package/data/Cli/starters/basic/src/tags/components/ColorRadioButton.tsx +44 -0
- package/data/Cli/starters/basic/src/tags/components/ColorRadioButtons.tsx +59 -0
- package/data/Cli/starters/basic/src/tags/components/CreateTagDialog.tsx +50 -0
- package/data/Cli/starters/basic/src/tags/components/CreateTagForm.tsx +100 -0
- package/data/Cli/starters/basic/src/tags/components/TagLabel.tsx +55 -0
- package/data/Cli/starters/basic/src/tags/components/colors.ts +8 -0
- package/data/Cli/starters/basic/src/tags/queries.ts +14 -0
- package/data/Cli/starters/basic/src/tasks/TasksPage.tsx +19 -0
- package/data/Cli/starters/basic/src/tasks/actions.ts +71 -0
- package/data/Cli/starters/basic/src/tasks/components/CreateTaskForm.tsx +103 -0
- package/data/Cli/starters/basic/src/tasks/components/TaskList.tsx +68 -0
- package/data/Cli/starters/basic/src/tasks/components/TaskListItem.tsx +56 -0
- package/data/Cli/starters/basic/src/tasks/queries.ts +21 -0
- package/data/Cli/starters/basic/tailwind.config.cjs +30 -0
- package/data/Cli/starters/basic/vite.config.ts +7 -0
- package/data/Cli/starters/minimal/main.wasp +14 -0
- package/data/Cli/starters/minimal/package.json +16 -0
- package/data/Cli/starters/minimal/schema.prisma +10 -0
- package/data/Cli/starters/minimal/src/Main.css +103 -0
- package/data/Cli/starters/minimal/src/MainPage.tsx +37 -0
- package/data/Cli/starters/minimal/src/assets/logo.svg +1 -0
- package/data/Cli/starters/minimal/vite.config.ts +7 -0
- package/data/Cli/starters/skeleton/.waspignore +4 -0
- package/data/Cli/starters/skeleton/.wasproot +1 -0
- package/data/Cli/starters/skeleton/public/.gitkeep +0 -0
- package/data/Cli/starters/skeleton/public/favicon.ico +0 -0
- package/data/Cli/starters/skeleton/src/vite-env.d.ts +7 -0
- package/data/Cli/starters/skeleton/tsconfig.json +28 -0
- package/data/Generator/templates/Dockerfile +72 -0
- package/data/Generator/templates/db/schema.prisma +24 -0
- package/data/Generator/templates/dockerignore +2 -0
- package/data/Generator/templates/react-app/README.md +21 -0
- package/data/Generator/templates/react-app/gitignore +23 -0
- package/data/Generator/templates/react-app/index.html +22 -0
- package/data/Generator/templates/react-app/netlify.toml +8 -0
- package/data/Generator/templates/react-app/npmrc +1 -0
- package/data/Generator/templates/react-app/package.json +30 -0
- package/data/Generator/templates/react-app/public/manifest.json +15 -0
- package/data/Generator/templates/react-app/src/auth/pages/OAuthCallback.tsx +96 -0
- package/data/Generator/templates/react-app/src/auth/pages/createAuthRequiredPage.jsx +40 -0
- package/data/Generator/templates/react-app/src/components/DefaultRootErrorBoundary.tsx +16 -0
- package/data/Generator/templates/react-app/src/components/FullPageWrapper.tsx +21 -0
- package/data/Generator/templates/react-app/src/components/Loader.module.css +37 -0
- package/data/Generator/templates/react-app/src/components/Loader.tsx +12 -0
- package/data/Generator/templates/react-app/src/components/Message.tsx +86 -0
- package/data/Generator/templates/react-app/src/index.tsx +47 -0
- package/data/Generator/templates/react-app/src/logo.png +0 -0
- package/data/Generator/templates/react-app/src/router.tsx +57 -0
- package/data/Generator/templates/react-app/src/stitches.config.js +33 -0
- package/data/Generator/templates/react-app/src/test/vitest/setup.ts +8 -0
- package/data/Generator/templates/react-app/src/utils.js +3 -0
- package/data/Generator/templates/react-app/src/vite-env.d.ts +1 -0
- package/data/Generator/templates/react-app/tsconfig.app.json +20 -0
- package/data/Generator/templates/react-app/tsconfig.json +11 -0
- package/data/Generator/templates/react-app/tsconfig.vite.json +16 -0
- package/data/Generator/templates/react-app/vite/detectServerImports.ts +53 -0
- package/data/Generator/templates/react-app/vite/validateEnv.ts +45 -0
- package/data/Generator/templates/react-app/vite.config.ts +74 -0
- package/data/Generator/templates/sdk/wasp/api/events.ts +11 -0
- package/data/Generator/templates/sdk/wasp/api/index.ts +136 -0
- package/data/Generator/templates/sdk/wasp/auth/email/actions/login.ts +13 -0
- package/data/Generator/templates/sdk/wasp/auth/email/actions/passwordReset.ts +22 -0
- package/data/Generator/templates/sdk/wasp/auth/email/actions/signup.ts +20 -0
- package/data/Generator/templates/sdk/wasp/auth/email/actions/verifyEmail.ts +14 -0
- package/data/Generator/templates/sdk/wasp/auth/email/index.ts +5 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/Auth.tsx +108 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/ForgotPassword.tsx +18 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/Login.tsx +18 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/ResetPassword.tsx +18 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/Signup.tsx +24 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/VerifyEmail.tsx +18 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/Form.tsx +107 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/Message.tsx +21 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/common/LoginSignupForm.tsx +356 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/email/ForgotPasswordForm.tsx +52 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/email/ResetPasswordForm.tsx +82 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/email/VerifyEmailForm.tsx +42 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/email/useEmail.ts +33 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/social/SocialButton.tsx +33 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/social/SocialIcons.tsx +78 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/internal/usernameAndPassword/useUsernameAndPassword.ts +29 -0
- package/data/Generator/templates/sdk/wasp/auth/forms/types.ts +52 -0
- package/data/Generator/templates/sdk/wasp/auth/helpers/_Provider.tsx +17 -0
- package/data/Generator/templates/sdk/wasp/auth/helpers/user.ts +15 -0
- package/data/Generator/templates/sdk/wasp/auth/index.ts +9 -0
- package/data/Generator/templates/sdk/wasp/auth/jwt.ts +22 -0
- package/data/Generator/templates/sdk/wasp/auth/logout.ts +18 -0
- package/data/Generator/templates/sdk/wasp/auth/lucia.ts +53 -0
- package/data/Generator/templates/sdk/wasp/auth/password.ts +36 -0
- package/data/Generator/templates/sdk/wasp/auth/providers/index.ts +9 -0
- package/data/Generator/templates/sdk/wasp/auth/providers/types.ts +68 -0
- package/data/Generator/templates/sdk/wasp/auth/session.ts +78 -0
- package/data/Generator/templates/sdk/wasp/auth/types.ts +2 -0
- package/data/Generator/templates/sdk/wasp/auth/useAuth.ts +37 -0
- package/data/Generator/templates/sdk/wasp/auth/user.ts +63 -0
- package/data/Generator/templates/sdk/wasp/auth/username/actions/login.ts +13 -0
- package/data/Generator/templates/sdk/wasp/auth/username/actions/signup.ts +20 -0
- package/data/Generator/templates/sdk/wasp/auth/username/index.ts +2 -0
- package/data/Generator/templates/sdk/wasp/auth/utils.ts +369 -0
- package/data/Generator/templates/sdk/wasp/auth/validation.ts +83 -0
- package/data/Generator/templates/sdk/wasp/client/auth/discord.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/auth/email.ts +5 -0
- package/data/Generator/templates/sdk/wasp/client/auth/github.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/auth/google.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/auth/index.ts +29 -0
- package/data/Generator/templates/sdk/wasp/client/auth/keycloak.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/auth/slack.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/auth/ui.ts +32 -0
- package/data/Generator/templates/sdk/wasp/client/auth/username.ts +2 -0
- package/data/Generator/templates/sdk/wasp/client/config.ts +14 -0
- package/data/Generator/templates/sdk/wasp/client/crud/_crud.ts +89 -0
- package/data/Generator/templates/sdk/wasp/client/crud/index.ts +4 -0
- package/data/Generator/templates/sdk/wasp/client/crud/operationsHelpers.ts +21 -0
- package/data/Generator/templates/sdk/wasp/client/env/schema.ts +22 -0
- package/data/Generator/templates/sdk/wasp/client/env.ts +5 -0
- package/data/Generator/templates/sdk/wasp/client/index.ts +17 -0
- package/data/Generator/templates/sdk/wasp/client/operations/actions/core.ts +49 -0
- package/data/Generator/templates/sdk/wasp/client/operations/actions/index.ts +13 -0
- package/data/Generator/templates/sdk/wasp/client/operations/hooks.ts +347 -0
- package/data/Generator/templates/sdk/wasp/client/operations/index.ts +22 -0
- package/data/Generator/templates/sdk/wasp/client/operations/internal/index.ts +22 -0
- package/data/Generator/templates/sdk/wasp/client/operations/internal/resources.js +83 -0
- package/data/Generator/templates/sdk/wasp/client/operations/internal/updateHandlersMap.js +37 -0
- package/data/Generator/templates/sdk/wasp/client/operations/queries/core.ts +91 -0
- package/data/Generator/templates/sdk/wasp/client/operations/queries/index.ts +16 -0
- package/data/Generator/templates/sdk/wasp/client/operations/queryClient.ts +34 -0
- package/data/Generator/templates/sdk/wasp/client/operations/rpc.ts +96 -0
- package/data/Generator/templates/sdk/wasp/client/router/Link.tsx +21 -0
- package/data/Generator/templates/sdk/wasp/client/router/index.ts +53 -0
- package/data/Generator/templates/sdk/wasp/client/router/linkHelpers.ts +48 -0
- package/data/Generator/templates/sdk/wasp/client/router/types.ts +98 -0
- package/data/Generator/templates/sdk/wasp/client/test/index.ts +1 -0
- package/data/Generator/templates/sdk/wasp/client/test/vitest/helpers.tsx +95 -0
- package/data/Generator/templates/sdk/wasp/client/webSocket/WebSocketProvider.tsx +77 -0
- package/data/Generator/templates/sdk/wasp/client/webSocket/index.ts +39 -0
- package/data/Generator/templates/sdk/wasp/core/auth.ts +40 -0
- package/data/Generator/templates/sdk/wasp/core/serialization/custom-register.ts +21 -0
- package/data/Generator/templates/sdk/wasp/core/serialization/index.ts +56 -0
- package/data/Generator/templates/sdk/wasp/core/serialization/prisma.ts +54 -0
- package/data/Generator/templates/sdk/wasp/core/stitches.config.ts +39 -0
- package/data/Generator/templates/sdk/wasp/core/storage.ts +50 -0
- package/data/Generator/templates/sdk/wasp/dev/index.ts +19 -0
- package/data/Generator/templates/sdk/wasp/entities/index.ts +28 -0
- package/data/Generator/templates/sdk/wasp/env/index.ts +9 -0
- package/data/Generator/templates/sdk/wasp/env/validation.ts +38 -0
- package/data/Generator/templates/sdk/wasp/package.json +151 -0
- package/data/Generator/templates/sdk/wasp/prisma-runtime-library.d.ts +17 -0
- package/data/Generator/templates/sdk/wasp/server/HttpError.ts +30 -0
- package/data/Generator/templates/sdk/wasp/server/_types/index.ts +105 -0
- package/data/Generator/templates/sdk/wasp/server/_types/taggedEntities.ts +26 -0
- package/data/Generator/templates/sdk/wasp/server/api/index.ts +44 -0
- package/data/Generator/templates/sdk/wasp/server/auth/email/index.ts +20 -0
- package/data/Generator/templates/sdk/wasp/server/auth/email/utils.ts +104 -0
- package/data/Generator/templates/sdk/wasp/server/auth/hooks.ts +188 -0
- package/data/Generator/templates/sdk/wasp/server/auth/index.ts +49 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/index.ts +38 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/oneTimeCode.ts +50 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/provider.ts +20 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/discord.ts +22 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/github.ts +20 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/google.ts +22 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/keycloak.ts +23 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/providers/slack.ts +22 -0
- package/data/Generator/templates/sdk/wasp/server/auth/oauth/redirect.ts +43 -0
- package/data/Generator/templates/sdk/wasp/server/auth/user.ts +148 -0
- package/data/Generator/templates/sdk/wasp/server/auth/username.ts +1 -0
- package/data/Generator/templates/sdk/wasp/server/config.ts +47 -0
- package/data/Generator/templates/sdk/wasp/server/crud/_operationTypes.ts +134 -0
- package/data/Generator/templates/sdk/wasp/server/crud/index.ts +5 -0
- package/data/Generator/templates/sdk/wasp/server/dbClient.ts +35 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/helpers.ts +40 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/index.ts +17 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/providers/dummy.ts +34 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/providers/mailgun.ts +31 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/providers/sendgrid.ts +44 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/providers/smtp.ts +29 -0
- package/data/Generator/templates/sdk/wasp/server/email/core/types.ts +59 -0
- package/data/Generator/templates/sdk/wasp/server/email/index.ts +39 -0
- package/data/Generator/templates/sdk/wasp/server/env.ts +168 -0
- package/data/Generator/templates/sdk/wasp/server/index.ts +17 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/_job.ts +39 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/core/job.ts +28 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/index.ts +3 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBoss.ts +76 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/pgBossJob.ts +230 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/core/pgBoss/types.ts +9 -0
- package/data/Generator/templates/sdk/wasp/server/jobs/index.ts +5 -0
- package/data/Generator/templates/sdk/wasp/server/middleware/globalMiddleware.ts +8 -0
- package/data/Generator/templates/sdk/wasp/server/middleware/index.ts +1 -0
- package/data/Generator/templates/sdk/wasp/server/operations/actions/index.ts +41 -0
- package/data/Generator/templates/sdk/wasp/server/operations/actions/types.ts +35 -0
- package/data/Generator/templates/sdk/wasp/server/operations/index.ts +13 -0
- package/data/Generator/templates/sdk/wasp/server/operations/queries/index.ts +42 -0
- package/data/Generator/templates/sdk/wasp/server/operations/queries/types.ts +36 -0
- package/data/Generator/templates/sdk/wasp/server/operations/wrappers.ts +242 -0
- package/data/Generator/templates/sdk/wasp/server/types/index.ts +11 -0
- package/data/Generator/templates/sdk/wasp/server/utils.ts +38 -0
- package/data/Generator/templates/sdk/wasp/server/webSocket/index.ts +57 -0
- package/data/Generator/templates/sdk/wasp/tsconfig.json +114 -0
- package/data/Generator/templates/sdk/wasp/universal/ansiColors.ts +14 -0
- package/data/Generator/templates/sdk/wasp/universal/predicates.ts +3 -0
- package/data/Generator/templates/sdk/wasp/universal/types.ts +74 -0
- package/data/Generator/templates/sdk/wasp/universal/url.ts +5 -0
- package/data/Generator/templates/sdk/wasp/universal/validators.ts +21 -0
- package/data/Generator/templates/sdk/wasp/vite-env.d.ts +1 -0
- package/data/Generator/templates/server/README.md +1 -0
- package/data/Generator/templates/server/gitignore +6 -0
- package/data/Generator/templates/server/nodemon.json +13 -0
- package/data/Generator/templates/server/npmrc +1 -0
- package/data/Generator/templates/server/package.json +27 -0
- package/data/Generator/templates/server/rollup.config.js +44 -0
- package/data/Generator/templates/server/src/actions/_action.ts +18 -0
- package/data/Generator/templates/server/src/app.js +36 -0
- package/data/Generator/templates/server/src/auth/hooks.ts +135 -0
- package/data/Generator/templates/server/src/auth/providers/config/discord.ts +69 -0
- package/data/Generator/templates/server/src/auth/providers/config/email.ts +96 -0
- package/data/Generator/templates/server/src/auth/providers/config/github.ts +78 -0
- package/data/Generator/templates/server/src/auth/providers/config/google.ts +65 -0
- package/data/Generator/templates/server/src/auth/providers/config/keycloak.ts +67 -0
- package/data/Generator/templates/server/src/auth/providers/config/slack.ts +65 -0
- package/data/Generator/templates/server/src/auth/providers/config/username.ts +33 -0
- package/data/Generator/templates/server/src/auth/providers/email/login.ts +66 -0
- package/data/Generator/templates/server/src/auth/providers/email/requestPasswordReset.ts +74 -0
- package/data/Generator/templates/server/src/auth/providers/email/resetPassword.ts +48 -0
- package/data/Generator/templates/server/src/auth/providers/email/signup.ts +165 -0
- package/data/Generator/templates/server/src/auth/providers/email/verifyEmail.ts +42 -0
- package/data/Generator/templates/server/src/auth/providers/index.ts +32 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/config.ts +19 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/cookies.ts +35 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/handler.ts +130 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/oneTimeCode.ts +39 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/state.ts +144 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/types.ts +7 -0
- package/data/Generator/templates/server/src/auth/providers/oauth/user.ts +139 -0
- package/data/Generator/templates/server/src/auth/providers/username/login.ts +64 -0
- package/data/Generator/templates/server/src/auth/providers/username/signup.ts +59 -0
- package/data/Generator/templates/server/src/crud/_operations.ts +184 -0
- package/data/Generator/templates/server/src/dbSeed.ts +37 -0
- package/data/Generator/templates/server/src/jobs/_job.ts +9 -0
- package/data/Generator/templates/server/src/jobs/core/allJobs.ts +8 -0
- package/data/Generator/templates/server/src/middleware/globalMiddleware.ts +45 -0
- package/data/Generator/templates/server/src/middleware/index.ts +1 -0
- package/data/Generator/templates/server/src/middleware/operations.ts +28 -0
- package/data/Generator/templates/server/src/queries/_query.ts +18 -0
- package/data/Generator/templates/server/src/routes/apis/index.ts +67 -0
- package/data/Generator/templates/server/src/routes/auth/index.js +16 -0
- package/data/Generator/templates/server/src/routes/auth/logout.ts +12 -0
- package/data/Generator/templates/server/src/routes/auth/me.ts +10 -0
- package/data/Generator/templates/server/src/routes/crud/_crud.ts +46 -0
- package/data/Generator/templates/server/src/routes/crud/index.ts +12 -0
- package/data/Generator/templates/server/src/routes/index.js +37 -0
- package/data/Generator/templates/server/src/routes/operations/_action.js +5 -0
- package/data/Generator/templates/server/src/routes/operations/_query.js +5 -0
- package/data/Generator/templates/server/src/routes/operations/index.js +18 -0
- package/data/Generator/templates/server/src/server.ts +76 -0
- package/data/Generator/templates/server/src/webSocket/initialization.ts +59 -0
- package/data/Generator/templates/server/tsconfig.json +41 -0
- package/data/Lsp/templates/ts/action.fn.ts +12 -0
- package/data/Lsp/templates/ts/operation.fn.js +7 -0
- package/data/Lsp/templates/ts/page.component.jsx +9 -0
- package/data/Lsp/templates/ts/query.fn.ts +12 -0
- package/main.js +9 -0
- package/package.json +1 -0
- package/readme.md +3 -0
- package/wasp-bin +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { login, signup } from '../../../username'
|
|
2
|
+
|
|
3
|
+
// PRIVATE API
|
|
4
|
+
export function useUsernameAndPassword({
|
|
5
|
+
onError,
|
|
6
|
+
onSuccess,
|
|
7
|
+
isLogin,
|
|
8
|
+
}: {
|
|
9
|
+
onError: (error: Error) => void
|
|
10
|
+
onSuccess: () => void
|
|
11
|
+
isLogin: boolean
|
|
12
|
+
}) {
|
|
13
|
+
async function handleSubmit(data) {
|
|
14
|
+
try {
|
|
15
|
+
if (!isLogin) {
|
|
16
|
+
await signup(data)
|
|
17
|
+
}
|
|
18
|
+
await login(data)
|
|
19
|
+
|
|
20
|
+
onSuccess()
|
|
21
|
+
} catch (err: unknown) {
|
|
22
|
+
onError(err as Error)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
handleSubmit,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { createTheme } from '@stitches/react'
|
|
3
|
+
import { UseFormReturn, RegisterOptions } from 'react-hook-form'
|
|
4
|
+
import type { LoginSignupFormFields } from './internal/common/LoginSignupForm'
|
|
5
|
+
|
|
6
|
+
// PRIVATE API
|
|
7
|
+
export enum State {
|
|
8
|
+
Login = 'login',
|
|
9
|
+
Signup = 'signup',
|
|
10
|
+
{=# isEmailAuthEnabled =}
|
|
11
|
+
ForgotPassword = 'forgot-password',
|
|
12
|
+
ResetPassword = 'reset-password',
|
|
13
|
+
VerifyEmail = 'verify-email',
|
|
14
|
+
{=/ isEmailAuthEnabled =}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// PUBLIC API
|
|
18
|
+
export type CustomizationOptions = {
|
|
19
|
+
logo?: string
|
|
20
|
+
socialLayout?: 'horizontal' | 'vertical'
|
|
21
|
+
appearance?: Parameters<typeof createTheme>[0]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// PRIVATE API
|
|
25
|
+
export type ErrorMessage = {
|
|
26
|
+
title: string
|
|
27
|
+
description?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// PRIVATE API
|
|
31
|
+
export type FormState = {
|
|
32
|
+
isLoading: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// PRIVATE API
|
|
36
|
+
export type AdditionalSignupFieldRenderFn = (
|
|
37
|
+
hookForm: UseFormReturn<LoginSignupFormFields>,
|
|
38
|
+
formState: FormState
|
|
39
|
+
) => React.ReactNode
|
|
40
|
+
|
|
41
|
+
// PRIVATE API
|
|
42
|
+
export type AdditionalSignupField = {
|
|
43
|
+
name: string
|
|
44
|
+
label: string
|
|
45
|
+
type: 'input' | 'textarea'
|
|
46
|
+
validations?: RegisterOptions<LoginSignupFormFields>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// PRIVATE API
|
|
50
|
+
export type AdditionalSignupFields =
|
|
51
|
+
| (AdditionalSignupField | AdditionalSignupFieldRenderFn)[]
|
|
52
|
+
| AdditionalSignupFieldRenderFn
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
|
|
3
|
+
import { config } from 'wasp/client'
|
|
4
|
+
import { SocialButton } from '../forms/internal/social/SocialButton'
|
|
5
|
+
import * as SocialIcons from '../forms/internal/social/SocialIcons'
|
|
6
|
+
|
|
7
|
+
// PUBLIC API
|
|
8
|
+
export const signInUrl: string = `${config.apiUrl}{= signInPath =}`
|
|
9
|
+
|
|
10
|
+
// PUBLIC API
|
|
11
|
+
export function SignInButton(): React.JSX.Element {
|
|
12
|
+
return (
|
|
13
|
+
<SocialButton href={signInUrl}>
|
|
14
|
+
<SocialIcons.{= displayName =} />
|
|
15
|
+
</SocialButton>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { setSessionId } from 'wasp/client/api'
|
|
2
|
+
import { invalidateAndRemoveQueries } from '../../client/operations/internal/resources.js'
|
|
3
|
+
|
|
4
|
+
// PRIVATE API
|
|
5
|
+
export async function initSession(sessionId: string): Promise<void> {
|
|
6
|
+
setSessionId(sessionId)
|
|
7
|
+
// We need to invalidate queries after login in order to get the correct user
|
|
8
|
+
// data in the React components (using `useAuth`).
|
|
9
|
+
// Redirects after login won't work properly without this.
|
|
10
|
+
|
|
11
|
+
// TODO(filip): We are currently removing all the queries, but we should
|
|
12
|
+
// remove only non-public, user-dependent queries - public queries are
|
|
13
|
+
// expected not to change in respect to the currently logged in user.
|
|
14
|
+
await invalidateAndRemoveQueries()
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as jwt from 'oslo/jwt'
|
|
2
|
+
import { config } from 'wasp/server'
|
|
3
|
+
|
|
4
|
+
const JWT_SECRET = new TextEncoder().encode(config.auth.jwtSecret)
|
|
5
|
+
const JWT_ALGORITHM = 'HS256'
|
|
6
|
+
|
|
7
|
+
// PRIVATE API
|
|
8
|
+
export function createJWT(
|
|
9
|
+
data: Parameters<typeof jwt.createJWT>[2],
|
|
10
|
+
options: Parameters<typeof jwt.createJWT>[3],
|
|
11
|
+
): Promise<string> {
|
|
12
|
+
return jwt.createJWT(JWT_ALGORITHM, JWT_SECRET, data, options)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// PRIVATE API
|
|
16
|
+
export async function validateJWT<Payload>(token: string): Promise<Payload> {
|
|
17
|
+
const { payload } = await jwt.validateJWT(JWT_ALGORITHM, JWT_SECRET, token)
|
|
18
|
+
return payload as Payload
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// PRIVATE API
|
|
22
|
+
export { TimeSpan } from 'oslo'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { api, removeLocalUserData } from 'wasp/client/api'
|
|
2
|
+
import { invalidateAndRemoveQueries } from '../client/operations/internal/resources.js'
|
|
3
|
+
|
|
4
|
+
// PUBLIC API
|
|
5
|
+
export default async function logout(): Promise<void> {
|
|
6
|
+
try {
|
|
7
|
+
await api.post('/auth/logout')
|
|
8
|
+
} finally {
|
|
9
|
+
// Even if the logout request fails, we still want to remove the local user data
|
|
10
|
+
// in case the logout failed because of a network error and the user walked away
|
|
11
|
+
// from the computer.
|
|
12
|
+
removeLocalUserData()
|
|
13
|
+
|
|
14
|
+
// TODO(filip): We are currently invalidating and removing all the queries, but
|
|
15
|
+
// we should remove only the non-public, user-dependent ones.
|
|
16
|
+
await invalidateAndRemoveQueries()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { Lucia } from "lucia";
|
|
3
|
+
import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
|
|
4
|
+
import { prisma } from 'wasp/server'
|
|
5
|
+
import { type {= userEntityUpper =} } from "wasp/entities"
|
|
6
|
+
|
|
7
|
+
const prismaAdapter = new PrismaAdapter(
|
|
8
|
+
prisma.{= sessionEntityLower =},
|
|
9
|
+
prisma.{= authEntityLower =},
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// PRIVATE API
|
|
13
|
+
/**
|
|
14
|
+
* We are using Lucia for session management.
|
|
15
|
+
*
|
|
16
|
+
* Some details:
|
|
17
|
+
* 1. We are using the Prisma adapter for Lucia.
|
|
18
|
+
* 2. We are not using cookies for session management. Instead, we are using
|
|
19
|
+
* the Authorization header to send the session token.
|
|
20
|
+
* 3. Our `Session` entity is connected to the `Auth` entity.
|
|
21
|
+
* 4. We are exposing the `userId` field from the `Auth` entity to
|
|
22
|
+
* make fetching the User easier.
|
|
23
|
+
*/
|
|
24
|
+
export const auth = new Lucia<{}, {
|
|
25
|
+
userId: {= userEntityUpper =}['id']
|
|
26
|
+
}>(prismaAdapter, {
|
|
27
|
+
// Since we are not using cookies, we don't need to set any cookie options.
|
|
28
|
+
// But in the future, if we decide to use cookies, we can set them here.
|
|
29
|
+
|
|
30
|
+
// sessionCookie: {
|
|
31
|
+
// name: "session",
|
|
32
|
+
// expires: true,
|
|
33
|
+
// attributes: {
|
|
34
|
+
// secure: !config.isDevelopment,
|
|
35
|
+
// sameSite: "lax",
|
|
36
|
+
// },
|
|
37
|
+
// },
|
|
38
|
+
getUserAttributes({ userId }) {
|
|
39
|
+
return {
|
|
40
|
+
userId,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
declare module "lucia" {
|
|
46
|
+
interface Register {
|
|
47
|
+
Lucia: typeof auth;
|
|
48
|
+
DatabaseSessionAttributes: {};
|
|
49
|
+
DatabaseUserAttributes: {
|
|
50
|
+
userId: {= userEntityUpper =}['id']
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { hash, verify, Version, type Options } from "@node-rs/argon2";
|
|
2
|
+
|
|
3
|
+
// The options are the same as the ones used in the oslo/password library
|
|
4
|
+
const hashingOptions: Options = {
|
|
5
|
+
memoryCost: 19456,
|
|
6
|
+
timeCost: 2,
|
|
7
|
+
outputLen: 32,
|
|
8
|
+
parallelism: 1,
|
|
9
|
+
version: Version.V0x13,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// PRIVATE API
|
|
13
|
+
export async function hashPassword(password: string): Promise<string> {
|
|
14
|
+
return hash(normalizePassword(password), hashingOptions);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// PRIVATE API
|
|
18
|
+
export async function verifyPassword(
|
|
19
|
+
hashedPassword: string,
|
|
20
|
+
password: string
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
const validPassword = await verify(
|
|
23
|
+
hashedPassword,
|
|
24
|
+
normalizePassword(password),
|
|
25
|
+
hashingOptions
|
|
26
|
+
);
|
|
27
|
+
if (!validPassword) {
|
|
28
|
+
throw new Error("Invalid password");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// We are normalising the password to ensure that the password is always hashed in the same way
|
|
33
|
+
// We have the same normalising process as oslo/password did in the past
|
|
34
|
+
function normalizePassword(password: string): string {
|
|
35
|
+
return password.normalize("NFKC");
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
|
|
3
|
+
{=# emailUserSignupFields.isDefined =}
|
|
4
|
+
export type { UserEmailSignupFields } from './types';
|
|
5
|
+
{=/ emailUserSignupFields.isDefined =}
|
|
6
|
+
|
|
7
|
+
{=# usernameAndPasswordUserSignupFields.isDefined =}
|
|
8
|
+
export type { UserUsernameAndPasswordSignupFields } from './types';
|
|
9
|
+
{=/ usernameAndPasswordUserSignupFields.isDefined =}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import type { Router, Request } from 'express'
|
|
3
|
+
import type { Prisma } from '@prisma/client'
|
|
4
|
+
import type { Expand, Exact } from 'wasp/universal/types'
|
|
5
|
+
import type { ProviderName } from '../utils'
|
|
6
|
+
|
|
7
|
+
// PUBLIC API
|
|
8
|
+
export function defineUserSignupFields<T extends UserSignupFields>(
|
|
9
|
+
fields: Exact<UserSignupFields, T>
|
|
10
|
+
): T {
|
|
11
|
+
return fields
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
{=# emailUserSignupFields.isDefined =}
|
|
15
|
+
{=& emailUserSignupFields.importStatement =}
|
|
16
|
+
// PUBLIC API
|
|
17
|
+
export type UserEmailSignupFields = InferUserSignupFields<typeof {= emailUserSignupFields.importIdentifier =}>;
|
|
18
|
+
{=/ emailUserSignupFields.isDefined =}
|
|
19
|
+
|
|
20
|
+
{=# usernameAndPasswordUserSignupFields.isDefined =}
|
|
21
|
+
{=& usernameAndPasswordUserSignupFields.importStatement =}
|
|
22
|
+
// PUBLIC API
|
|
23
|
+
export type UserUsernameAndPasswordSignupFields = InferUserSignupFields<typeof {= usernameAndPasswordUserSignupFields.importIdentifier =}>;
|
|
24
|
+
{=/ usernameAndPasswordUserSignupFields.isDefined =}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the result types from a UserSignupFields object.
|
|
28
|
+
*
|
|
29
|
+
* This type transforms an object containing field getter functions
|
|
30
|
+
* into an object with the same keys but whose values are the return types
|
|
31
|
+
* of those functions.
|
|
32
|
+
*/
|
|
33
|
+
type InferUserSignupFields<T extends UserSignupFields> = {
|
|
34
|
+
[K in keyof T]: T[K] extends FieldGetter<PossibleUserFieldValues>
|
|
35
|
+
? ReturnType<T[K]>
|
|
36
|
+
: never
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type UserEntityCreateInput = Prisma.{= userEntityUpper =}CreateInput
|
|
40
|
+
|
|
41
|
+
// PRIVATE API
|
|
42
|
+
export type ProviderConfig = {
|
|
43
|
+
// Unique provider identifier, used as part of URL paths
|
|
44
|
+
id: ProviderName;
|
|
45
|
+
displayName: string;
|
|
46
|
+
// Every provider must have a setupRouter method which returns the Express router.
|
|
47
|
+
// In this function we are flexibile to do what ever is necessary to make the provider work.
|
|
48
|
+
createRouter(provider: ProviderConfig): Router;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// PRIVATE API
|
|
52
|
+
export type RequestWithWasp = Request & { wasp?: { [key: string]: any } }
|
|
53
|
+
|
|
54
|
+
// PRIVATE API
|
|
55
|
+
export type PossibleUserFields = Expand<Partial<UserEntityCreateInput>>
|
|
56
|
+
|
|
57
|
+
// PRIVATE API
|
|
58
|
+
export type UserSignupFields = {
|
|
59
|
+
[key in keyof PossibleUserFields]: FieldGetter<
|
|
60
|
+
PossibleUserFields[key]
|
|
61
|
+
>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type FieldGetter<T extends PossibleUserFieldValues> = (
|
|
65
|
+
data: { [key: string]: unknown }
|
|
66
|
+
) => Promise<T | undefined> | T | undefined
|
|
67
|
+
|
|
68
|
+
type PossibleUserFieldValues = PossibleUserFields[keyof PossibleUserFields]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { Request as ExpressRequest } from "express";
|
|
3
|
+
|
|
4
|
+
import { type {= userEntityUpper =} } from '../entities/index.js';
|
|
5
|
+
import { type AuthUserData } from '../server/auth/user.js';
|
|
6
|
+
|
|
7
|
+
import { auth } from "./lucia.js";
|
|
8
|
+
import type { Session } from "lucia";
|
|
9
|
+
import { createInvalidCredentialsError } from "./utils.js";
|
|
10
|
+
|
|
11
|
+
import { prisma } from 'wasp/server';
|
|
12
|
+
import { createAuthUserData } from "../server/auth/user.js";
|
|
13
|
+
|
|
14
|
+
// PRIVATE API
|
|
15
|
+
// Creates a new session for the `authId` in the database
|
|
16
|
+
export async function createSession(authId: string): Promise<Session> {
|
|
17
|
+
return auth.createSession(authId, {});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type SessionAndUser = {
|
|
21
|
+
session: Session;
|
|
22
|
+
user: AuthUserData;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// PRIVATE API
|
|
26
|
+
export async function getSessionAndUserFromBearerToken(req: ExpressRequest): Promise<SessionAndUser | null> {
|
|
27
|
+
const authorizationHeader = req.headers["authorization"];
|
|
28
|
+
|
|
29
|
+
if (typeof authorizationHeader !== "string") {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const sessionId = auth.readBearerToken(authorizationHeader);
|
|
34
|
+
if (!sessionId) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return getSessionAndUserFromSessionId(sessionId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// PRIVATE API
|
|
42
|
+
export async function getSessionAndUserFromSessionId(sessionId: string): Promise<SessionAndUser | null> {
|
|
43
|
+
const { session, user: authEntity } = await auth.validateSession(sessionId);
|
|
44
|
+
|
|
45
|
+
if (!session || !authEntity) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
session,
|
|
51
|
+
user: await getAuthUserData(authEntity.userId)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function getAuthUserData(userId: {= userEntityUpper =}['id']): Promise<AuthUserData> {
|
|
56
|
+
const user = await prisma.{= userEntityLower =}
|
|
57
|
+
.findUnique({
|
|
58
|
+
where: { id: userId },
|
|
59
|
+
include: {
|
|
60
|
+
{= authFieldOnUserEntityName =}: {
|
|
61
|
+
include: {
|
|
62
|
+
{= identitiesFieldOnAuthEntityName =}: true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
if (!user) {
|
|
69
|
+
throw createInvalidCredentialsError()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return createAuthUserData(user);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// PRIVATE API
|
|
76
|
+
export function invalidateSession(sessionId: string): Promise<void> {
|
|
77
|
+
return auth.invalidateSession(sessionId);
|
|
78
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { deserialize } from 'wasp/core/serialization'
|
|
3
|
+
import { useQuery, buildAndRegisterQuery } from 'wasp/client/operations'
|
|
4
|
+
import type { QueryFunction, Query } from 'wasp/client/operations/rpc'
|
|
5
|
+
import { api, handleApiError } from 'wasp/client/api'
|
|
6
|
+
import { HttpMethod } from 'wasp/client'
|
|
7
|
+
import type { AuthUser, AuthUserData } from '../server/auth/user.js'
|
|
8
|
+
import { makeAuthUserIfPossible } from '../auth/user.js'
|
|
9
|
+
import { UseQueryResult } from '@tanstack/react-query'
|
|
10
|
+
|
|
11
|
+
// PUBLIC API
|
|
12
|
+
export const getMe: Query<void, AuthUser | null> = createUserGetter()
|
|
13
|
+
|
|
14
|
+
// PUBLIC API
|
|
15
|
+
export default function useAuth(): UseQueryResult<AuthUser | null> {
|
|
16
|
+
return useQuery(getMe)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createUserGetter(): Query<void, AuthUser | null> {
|
|
20
|
+
const getMeRelativePath = 'auth/me'
|
|
21
|
+
const getMeRoute = { method: HttpMethod.Get, path: `/${getMeRelativePath}` }
|
|
22
|
+
const getMe: QueryFunction<void, AuthUser | null> = async () => {
|
|
23
|
+
try {
|
|
24
|
+
const response = await api.get(getMeRoute.path)
|
|
25
|
+
const userData = deserialize<AuthUserData | null>(response.data)
|
|
26
|
+
return makeAuthUserIfPossible(userData)
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw handleApiError(error)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return buildAndRegisterQuery(getMe, {
|
|
33
|
+
queryCacheKey: [getMeRelativePath],
|
|
34
|
+
queryRoute: getMeRoute,
|
|
35
|
+
entitiesUsed: {=& entitiesGetMeDependsOn =},
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ProviderName } from '../server/_types/index.js'
|
|
2
|
+
import type {
|
|
3
|
+
AuthUserData,
|
|
4
|
+
AuthUser,
|
|
5
|
+
UserEntityWithAuth,
|
|
6
|
+
} from '../server/auth/user.js'
|
|
7
|
+
import { isNotNull } from '../universal/predicates.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* We split the user.ts code into two files to avoid some server-only
|
|
11
|
+
* code (Oslo's hashing functions) being imported on the client.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// PUBLIC API
|
|
15
|
+
export function getEmail(user: UserEntityWithAuth): string | null {
|
|
16
|
+
return findUserIdentity(user, "email")?.providerUserId ?? null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// PUBLIC API
|
|
20
|
+
export function getUsername(user: UserEntityWithAuth): string | null {
|
|
21
|
+
return findUserIdentity(user, "username")?.providerUserId ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// PUBLIC API
|
|
25
|
+
export function getFirstProviderUserId(user?: UserEntityWithAuth): string | null {
|
|
26
|
+
if (!user || !user.auth || !user.auth.identities || user.auth.identities.length === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return user.auth.identities[0].providerUserId ?? null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// PRIVATE API (used in SDK and server)
|
|
34
|
+
export type { AuthUserData, AuthUser } from '../server/auth/user.js'
|
|
35
|
+
|
|
36
|
+
// PRIVATE API (used in SDK and server)
|
|
37
|
+
export function makeAuthUserIfPossible(user: null): null
|
|
38
|
+
export function makeAuthUserIfPossible(user: AuthUserData): AuthUser
|
|
39
|
+
export function makeAuthUserIfPossible(user: AuthUserData | null): AuthUser | null
|
|
40
|
+
export function makeAuthUserIfPossible(
|
|
41
|
+
user: AuthUserData | null,
|
|
42
|
+
): AuthUser | null {
|
|
43
|
+
return user ? makeAuthUser(user) : null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function makeAuthUser(data: AuthUserData): AuthUser {
|
|
47
|
+
return {
|
|
48
|
+
...data,
|
|
49
|
+
getFirstProviderUserId: () => {
|
|
50
|
+
const identities = Object.values(data.identities).filter(isNotNull);
|
|
51
|
+
return identities.length > 0 ? identities[0].id : null;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function findUserIdentity(user: UserEntityWithAuth, providerName: ProviderName): NonNullable<UserEntityWithAuth['auth']>['identities'][number] | null {
|
|
57
|
+
if (!user.auth) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return user.auth.identities.find(
|
|
61
|
+
(identity) => identity.providerName === providerName
|
|
62
|
+
) ?? null;
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { api, handleApiError } from 'wasp/client/api'
|
|
3
|
+
import { initSession } from '../../helpers/user'
|
|
4
|
+
|
|
5
|
+
export async function login(data: { username: string, password: string }): Promise<void> {
|
|
6
|
+
try {
|
|
7
|
+
const response = await api.post('{= loginPath =}', data)
|
|
8
|
+
|
|
9
|
+
await initSession(response.data.sessionId)
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw handleApiError(error)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{{={= =}=}}
|
|
2
|
+
import { api, handleApiError } from 'wasp/client/api'
|
|
3
|
+
{=# usernameAndPasswordUserSignupFields.isDefined =}
|
|
4
|
+
import { type UserUsernameAndPasswordSignupFields } from '../../providers'
|
|
5
|
+
{=/ usernameAndPasswordUserSignupFields.isDefined =}
|
|
6
|
+
|
|
7
|
+
type UsernameSignupData = {
|
|
8
|
+
username: string
|
|
9
|
+
password: string
|
|
10
|
+
}{=# usernameAndPasswordUserSignupFields.isDefined =} & UserUsernameAndPasswordSignupFields{=/ usernameAndPasswordUserSignupFields.isDefined =}
|
|
11
|
+
|
|
12
|
+
// PUBLIC API
|
|
13
|
+
export async function signup(data: UsernameSignupData): Promise<void> {
|
|
14
|
+
try {
|
|
15
|
+
await api.post('{= signupPath =}', data)
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw handleApiError(error)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|