-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Update AuthUser to offer a better DX #1915
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c7d3811
Update AuthUser API
infomiho 4e0547f
Updates types. Cleanup.
infomiho ccf9dce
Fixes types
infomiho 87ae042
e2e tests
infomiho e704c2f
Updates headless tests
infomiho babbf29
Split user.ts file. Improve types. Combine ID and data into a single …
infomiho 3a8f82c
Update tests
infomiho 7fb8247
Cleanup
infomiho c3b1fa9
Drops findUserIdentity
infomiho 9da36f5
WIP docs change
infomiho b9528a0
Removes _rawUser property on AuthUser
infomiho 689e17e
Update docs on the new user API
infomiho 40b9414
Fixes crud-testing not to leak password hash
infomiho c77eb33
AuthUser docs
infomiho 3577d36
Comments
infomiho 1d52368
PR comments
infomiho cd46f61
PR comments
infomiho 6bd82af
Updates the Changelog
infomiho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
// PUBLIC | ||
export type { AuthUser } from '../server/_types' | ||
// PUBLIC API | ||
export { | ||
getEmail, | ||
getUsername, | ||
getFirstProviderUserId, | ||
} from './user.js' | ||
|
||
export { getEmail, getUsername, getFirstProviderUserId, findUserIdentity } from './user.js' | ||
// PUBLIC API | ||
export { | ||
type AuthUser, | ||
} from '../server/auth/user.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// todo(filip): turn into a proper import/path | ||
export type { AuthUser, ProviderName, DeserializedAuthIdentity } from 'wasp/server/_types' | ||
export type { ProviderName } from 'wasp/server/_types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
import type { AuthUser, ProviderName, DeserializedAuthIdentity } from './types' | ||
{{={= =}=}} | ||
import { type {= authIdentityEntityName =} } from '../entities/index.js' | ||
import { type ProviderName } from '../server/_types/index.js' | ||
/** | ||
* We split the user.ts code into two files to avoid some server-only | ||
* code (Oslo's hashing functions) being imported on the client. | ||
*/ | ||
import { type UserEntityWithAuth } from '../server/auth/user.js' | ||
|
||
// PUBLIC API | ||
export function getEmail(user: AuthUser): string | null { | ||
export function getEmail(user: UserEntityWithAuth): string | null { | ||
return findUserIdentity(user, "email")?.providerUserId ?? null; | ||
} | ||
|
||
// PUBLIC API | ||
export function getUsername(user: AuthUser): string | null { | ||
export function getUsername(user: UserEntityWithAuth): string | null { | ||
return findUserIdentity(user, "username")?.providerUserId ?? null; | ||
} | ||
|
||
// PUBLIC API | ||
export function getFirstProviderUserId(user?: AuthUser): string | null { | ||
export function getFirstProviderUserId(user?: UserEntityWithAuth): string | null { | ||
if (!user || !user.auth || !user.auth.identities || user.auth.identities.length === 0) { | ||
return null; | ||
} | ||
|
||
return user.auth.identities[0].providerUserId ?? null; | ||
} | ||
|
||
// PUBLIC API | ||
export function findUserIdentity(user: AuthUser, providerName: ProviderName): DeserializedAuthIdentity | undefined { | ||
function findUserIdentity(user: UserEntityWithAuth, providerName: ProviderName): {= authIdentityEntityName =} | null { | ||
if (!user.auth) { | ||
return null; | ||
} | ||
return user.auth.identities.find( | ||
(identity) => identity.providerName === providerName | ||
); | ||
) ?? null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This TODO is now resolved yay! Since the type and the runtime value are based on the same logic.