-
-
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 26 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
packages | ||
Generator/libs/*.tgz | ||
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 mentioned this in a different thread, but why don't we ignore the entire libs directory and have the exact same setup as we do with packages? |
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. How come we're using a different system than the one we use for Specifically, why are we adding this folder to version control instead of creating during |
infomiho marked this conversation as resolved.
Show resolved
Hide resolved
|
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,13 +1,14 @@ | ||
import { useContext } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { useAuthContext } from '@wasp.sh/libs-auth/client' | ||
|
||
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/libs-auth"; | ||
|
||
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/libs-auth"; | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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/libs-auth"; | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { parseCookies } from "@wasp.sh/libs-auth"; | ||
|
||
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"; | ||
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. Double quotes? Is this a formatting mistake? 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'm not sure if we are consistent with formatting in the templates, I'll revert the change to keep the diff cleaner 👍 |
||
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?