-
-
Notifications
You must be signed in to change notification settings - Fork 181
feature): [gotrue-js] Refactor return and error types #301
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
Conversation
@kangmingtay --
Promise<
| {
session: Session | null
user: User | null
provider?: Provider
url?: string | null
error: null
}
| {
session: Session | null
user: User | null
provider?: Provider
url?: string | null
error: AuthError
}
> But perhaps I should enumerate the possibilities (I did so when there were fewer nullable cases)?
For example: Promise<
| {
data: User
error: null
}
| {
data: Session
error: null
}
| { data: null; error: AuthError }
> I could make this a |
Also what changes to the documentation need to be made? Any new error handling? |
Also, should the release and package be updated to 2?
and RELEASES?
|
Would it make sense to just have everything in the |
Looking at this, it makes sense to remove the type check for @alaister also has some thoughts on why he prefers not to have custom types for these |
One of the more confusing aspects of this api is the use of user vs session vs data. Sometimes data is a user, sometimes a session, sometimes it returns user and sometimes session. Is this the time to refactor to be consistent and not use “data” when a user or session is returned? For example: let session: Session | null = null
let user: User | null = null
if ((data as Session).access_token) {
session = data as Session
user = session.user as User
this._saveSession(session)
this._notifyAllSubscribers('SIGNED_IN')
}
if ((data as User).id) {
user = data as User
}
return { user, session, error: null } In a It looks like It strikes me that when authenticating, I'd get a Session. But when querying for some user account info, I'd get a User. No? The |
fa74f2a
to
a4f7116
Compare
This PR is ready for review. Should include latest from next branch. I tried in most places to make the return types consistent -- so fewer cases of where "data" meant "User" or "data" meant "Session" and instead return user or session so the developer knows what type that the "data" really is. Also, the feature to include the |
🎉 This PR is included in version 1.23.0-next.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 2.0.0-rc.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What kind of change does this PR introduce?
This PR refactors the return types for the
gotrue-js
client to match the pattern used bystorage-js
.See: supabase/storage-js#60
What is the current behavior?
See: supabase/storage-js#60
What is the new behavior?
Additional context
Tests pass.