-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Moving logic from templates to libs #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 71 commits
b4e1769
8b708bb
49d979c
a352e57
97a6838
121901f
4e248ae
ac9d038
3840e58
db8aaeb
ac55723
6dfc790
7a84ae8
e8c955a
f0cfe95
2f77c1c
36b720c
083fecb
9a70244
b450ef2
00e6fbf
90eab52
6b6b2f7
3c818cd
7e76f65
43aaac5
1073098
828b096
aa05550
c4099d5
82f258c
c3454d7
22958f5
9f3a53a
a06e101
1e1d36c
190e789
fb548b0
48dfe49
58fe09a
bd54fb4
ef0182b
8851649
9fc9e17
8a4ce86
a88c972
5bd2680
4f0a8e7
211a04b
03066ee
ae1255b
b9ace98
f50e54b
2478372
cd5347c
438314a
10803d4
52fe7f2
f2df493
b234395
669faca
4e6ddbb
5f3078e
b0417a3
a695db1
cd6940b
5771e1f
4b5a1c7
133e837
bcab437
f1a21e0
563c00c
7c08e2d
e2d5eda
12b925a
0fae11c
ac02cca
6ecacc3
075cc77
1587964
279d1b4
38fdbe0
0bec41e
68a4035
500f574
2dc8399
97f1a49
d07b368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import Wasp.Cli.Terminal (title) | |
import qualified Wasp.ExternalConfig.Npm.Dependency as Npm.Dependency | ||
import qualified Wasp.Generator.NpmDependencies as N | ||
import qualified Wasp.Generator.ServerGenerator as ServerGenerator | ||
import qualified Wasp.Generator.WaspLibs.AvailableLibs as WaspLibs.AvailableLibs | ||
import qualified Wasp.Generator.WaspLibs.WaspLib as WaspLib | ||
import qualified Wasp.Generator.WebAppGenerator as WebAppGenerator | ||
import Wasp.Project (analyzeWaspProject) | ||
import qualified Wasp.Util.Terminal as Term | ||
|
@@ -27,24 +29,25 @@ deps = do | |
(throwError . CommandError "Determining dependencies failed due to a compilation error in your Wasp project" . unwords) | ||
return | ||
appSpecOrAnalyzerErrors | ||
waspLibs <- liftIO WaspLibs.AvailableLibs.makeWaspLibs | ||
|
||
liftIO $ putStrLn $ depsMessage appSpec | ||
liftIO $ putStrLn $ depsMessage appSpec waspLibs | ||
|
||
depsMessage :: AppSpec -> String | ||
depsMessage appSpec = | ||
depsMessage :: AppSpec -> [WaspLib.WaspLib] -> String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should be showing the libraries, they should be transparent and have no significative version number by themselves. And if I got it right, users should not be importing the libraries. |
||
depsMessage appSpec waspLibs = | ||
unlines $ | ||
[ "", | ||
title "Below are listed the dependencies that Wasp uses in your project. You can import and use these directly in the code as if you specified them yourself, but you can't change their versions.", | ||
"" | ||
] | ||
++ printDeps | ||
"Server dependencies:" | ||
( N.waspDependencies $ ServerGenerator.npmDepsForWasp appSpec | ||
( N.waspDependencies $ ServerGenerator.npmDepsForWasp appSpec waspLibs | ||
) | ||
++ [""] | ||
++ printDeps | ||
"Server devDependencies:" | ||
( N.waspDevDependencies $ ServerGenerator.npmDepsForWasp appSpec | ||
( N.waspDevDependencies $ ServerGenerator.npmDepsForWasp appSpec waspLibs | ||
) | ||
++ [""] | ||
++ printDeps | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
packages | ||
Generator/libs/*.tgz | ||
|
|
infomiho marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ COPY package-lock.json . | |
COPY tsconfig*.json . | ||
COPY server .wasp/build/server | ||
COPY sdk .wasp/out/sdk | ||
# We copy Wasp libs twice, because server needs them in .wasp/build/libs | ||
# and SDK needs them in .wasp/out/libs becuase the SDK needs to live in the | ||
# out directory to be accessible to the client code: https://github.com/wasp-lang/wasp/issues/1769 | ||
COPY libs .wasp/build/libs | ||
COPY libs .wasp/out/libs | ||
Martinsos marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+41
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, something seems off with this setup. We're installing libs from tarballs but still have to copy the root directory twice. It seems we should just copy the tarballs and delegate the installation to NPM. Was this undoable because of the linked issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we are copying only the tarballs in this case the tree libs
libs
└── wasp.sh-lib-auth-cde4448e.tgz The SDK installs it like this: {
"dependencies": "file:../../libs/wasp.sh-lib-auth-cde4448e.tgz"
} and the server installs it like this: {
"dependencies": "file:../libs/wasp.sh-lib-auth-cde4448e.tgz"
} Because of the linked issue we have to have both I didn't want to perpetuate the hack by modifying the install location for the {
"dependencies": "file:../../out/libs/wasp.sh-lib-auth-cde4448e.tgz"
} Once we come up with a solution for the libs needing to live in the |
||
# Install npm packages, resulting in node_modules/. | ||
RUN npm install && cd .wasp/build/server && npm install | ||
{=# usingPrisma =} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ const defaultViteConfig = { | |||||
detectServerImports(), | ||||||
], | ||||||
optimizeDeps: { | ||||||
exclude: ['wasp'] | ||||||
exclude: {=& depsExcludedFromOptimization =} | ||||||
|
exclude: {=& depsExcludedFromOptimization =} | |
exclude: {=& depsExcludedFromOptimization =} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,14 +1,13 @@ | ||||||
{{={= =}=}} | ||||||
import { useState, createContext, useMemo } from 'react' | ||||||
import { useState, useMemo, type CSSProperties } from 'react' | ||||||
|
import { useState, useMemo, type CSSProperties } from 'react' | |
import { useState, useMemo } from 'react' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { useContext } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { useAuthContext } from '@wasp.sh/lib-auth/sdk/browser' | ||
|
||
import { requestPasswordReset } from '../../../email/actions/passwordReset.js' | ||
import { Form, FormItemGroup, FormLabel, FormInput, SubmitButton, FormError } from '../Form' | ||
import { AuthContext } from '../../Auth' | ||
|
||
|
||
// PRIVATE API | ||
export const ForgotPasswordForm = () => { | ||
const { register, handleSubmit, reset, formState: { errors } } = useForm<{ email: string }>() | ||
const { isLoading, setErrorMessage, setSuccessMessage, setIsLoading } = useContext(AuthContext) | ||
const { isLoading, setErrorMessage, setSuccessMessage, setIsLoading } = useAuthContext() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When doing big PRs like this, I advise staying away from all other changes, no matter how minor. This can stay but we should apply the principle to future PRs. Btw, update the public API table if necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think it's good that he made this change, it's scoped enough to be a demonstration and a proof that it works, without big changes otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a POC where I had to get a feel for how the lib will ship browser code - I didn't want to ship the system which would be completely wrong for browser stuff. I can remove this bit if you want and add it in a separate PR. |
||
|
||
const onSubmit = async (data) => { | ||
setIsLoading(true) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
import * as jwt from 'oslo/jwt' | ||
import { config } from 'wasp/server' | ||
import { createJWTHelpers } from "@wasp.sh/lib-auth/sdk"; | ||
|
||
const JWT_SECRET = new TextEncoder().encode(config.auth.jwtSecret) | ||
const JWT_ALGORITHM = 'HS256' | ||
import { config } from "wasp/server"; | ||
|
||
// PRIVATE API | ||
export function createJWT( | ||
data: Parameters<typeof jwt.createJWT>[2], | ||
options: Parameters<typeof jwt.createJWT>[3], | ||
): Promise<string> { | ||
return jwt.createJWT(JWT_ALGORITHM, JWT_SECRET, data, options) | ||
} | ||
const JWT_SECRET = new TextEncoder().encode(config.auth.jwtSecret); | ||
const JWT_ALGORITHM = "HS256"; | ||
|
||
// PRIVATE API | ||
export async function validateJWT<Payload>(token: string): Promise<Payload> { | ||
const { payload } = await jwt.validateJWT(JWT_ALGORITHM, JWT_SECRET, token) | ||
return payload as Payload | ||
} | ||
export const { createJWT, validateJWT } = createJWTHelpers( | ||
JWT_SECRET, | ||
JWT_ALGORITHM, | ||
); | ||
|
||
// PRIVATE API | ||
export { TimeSpan } from 'oslo' | ||
export { TimeSpan } from "@wasp.sh/lib-auth/sdk"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1 @@ | ||
import { hash, verify, Version, type Options } from "@node-rs/argon2"; | ||
|
||
// The options are the same as the ones used in the oslo/password library | ||
const hashingOptions: Options = { | ||
memoryCost: 19456, | ||
timeCost: 2, | ||
outputLen: 32, | ||
parallelism: 1, | ||
version: Version.V0x13, | ||
}; | ||
|
||
// PRIVATE API | ||
export async function hashPassword(password: string): Promise<string> { | ||
return hash(normalizePassword(password), hashingOptions); | ||
} | ||
|
||
// PRIVATE API | ||
export async function verifyPassword( | ||
hashedPassword: string, | ||
password: string | ||
): Promise<void> { | ||
const validPassword = await verify( | ||
hashedPassword, | ||
normalizePassword(password), | ||
hashingOptions | ||
); | ||
if (!validPassword) { | ||
throw new Error("Invalid password"); | ||
} | ||
} | ||
|
||
// We are normalising the password to ensure that the password is always hashed in the same way | ||
// We have the same normalising process as oslo/password did in the past | ||
function normalizePassword(password: string): string { | ||
return password.normalize("NFKC"); | ||
} | ||
export { hashPassword, verifyPassword } from "@wasp.sh/lib-auth/sdk"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { parseCookies } from "@wasp.sh/lib-auth/server"; | ||
|
||
import { | ||
Request as ExpressRequest, | ||
Response as ExpressResponse, | ||
} from 'express'; | ||
import { parseCookies } from 'oslo/cookie'; | ||
} from "express"; | ||
|
||
import type { ProviderConfig } from 'wasp/auth/providers/types'; | ||
import { config } from 'wasp/server'; | ||
import type { ProviderConfig } from "wasp/auth/providers/types"; | ||
|
||
import { config } from "wasp/server"; | ||
|
||
import type { OAuthStateFieldName } from './state'; | ||
import type { OAuthStateFieldName } from "./state"; | ||
|
||
export function setOAuthCookieValue( | ||
provider: ProviderConfig, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be using
./run
instead of the script in all cases?