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
Fix: type issue on the dbAuth generated pages #3068
Conversation
useEffect(() => { | ||
usernameRef.current.focus() | ||
}, []) | ||
|
||
const onSubmit = async (data) => { | ||
const response = await logIn({ ...data }) | ||
const response: any = await logIn({ ...data }) |
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.
Just a quick fix, the decent fix should be proper type the logIn method, but does this logIn
being used for all scenarios and some of them do return while some of them are not? That gonna make it more interesting...
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 don't think we need to type the response here, the type can probably be inferred from the login method - which I suppose currently is any
.
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.
You are right, should be inferred, the current type is void
which causes the problem.
this any
is just for removing that annoying red underline in the IDE xD,
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.
Gotcha - let me check the typings for useAuth :)
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.
Albert, what do you think of modifying the return types in https://github.com/redwoodjs/redwood/blob/main/packages/auth/src/AuthProvider.tsx#L23-L25 to be Promise<any>
or Promise<unknown>
?
The challenge here is that we don't know the exact type - because it varies per auth provider. I have plans to improve these typings, but will have to wait a little
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.
good idea, that would be a better fix since this is the source. Promise<any> would be better because unknown means the we have to cast it when use it.
We can just let that function return Promise<any> and properly type it when the API design is finalized.
I'd love to approve this, but I would have no idea if this fix is working or not (types are the bane of my existence). Can I substitute @dac09 for me? :) |
packages/cli/src/commands/generate/dbAuth/templates/login.tsx.template
Outdated
Show resolved
Hide resolved
@@ -22,13 +22,13 @@ const SignupPage = () => { | |||
}, [isAuthenticated]) | |||
|
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.
Same comments as login.tsx
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.
done :)
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.
Awaiting changes to AuthProvider type
Done :) Sorry was sleeping yesterday @dac09 |
Haha no worries @Albert-Gao - just marked the PR to stay organised. Appreciate this - will review in the morning after my sleep :) |
Cheers @Albert-Gao! 🚀 |
My pleasure 😀 |
close #3067