-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mihovil Ilakovac <[email protected]>
- Loading branch information
Showing
14 changed files
with
136 additions
and
109 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// PUBLIC | ||
export type { AuthUser } from '../server/_types' | ||
|
||
export { getEmail, getUsername, getFirstProviderUserId, findUserIdentity } from './user.js' | ||
export { | ||
getEmail, | ||
getUsername, | ||
getFirstProviderUserId, | ||
findUserIdentity, | ||
type AuthUser, | ||
} from './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, DeserializedAuthIdentity } 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
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,4 @@ | ||
import { type AuthUser as User } from 'wasp/auth' | ||
import { type AuthUser } from 'wasp/auth' | ||
import { mockServer, renderInContext } from 'wasp/client/test' | ||
import { getTasks, getDate } from 'wasp/client/operations' | ||
import { test, expect } from 'vitest' | ||
|
@@ -7,6 +7,7 @@ import { screen } from '@testing-library/react' | |
import Todo, { areThereAnyTasks } from './Todo' | ||
import { App } from './App' | ||
import { getMe } from 'wasp/client/auth' | ||
import { createAuthUser } from 'wasp/auth/user' | ||
|
||
test('areThereAnyTasks', () => { | ||
expect(areThereAnyTasks([])).toBe(false) | ||
|
@@ -35,7 +36,7 @@ test('handles mock data', async () => { | |
screen.debug() | ||
}) | ||
|
||
const mockUser = { | ||
const mockUser = createAuthUser({ | ||
id: 12, | ||
auth: { | ||
id: '123', | ||
|
@@ -45,12 +46,12 @@ const mockUser = { | |
authId: '123', | ||
providerName: 'email', | ||
providerUserId: '[email protected]', | ||
providerData: '', | ||
providerData: '{}', | ||
}, | ||
], | ||
}, | ||
address: null, | ||
} satisfies User | ||
}) | ||
|
||
test('handles multiple mock data sources', async () => { | ||
mockQuery(getMe, mockUser) | ||
|
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
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,42 +1,27 @@ | ||
import { getEmail, findUserIdentity, type AuthUser as User } from 'wasp/auth' | ||
import { getEmail, findUserIdentity, type AuthUser } from 'wasp/auth' | ||
|
||
export function getName(user?: User) { | ||
export function getName(user?: AuthUser) { | ||
if (!user) { | ||
return null | ||
} | ||
|
||
// We use multiple auth methods, so we need to check which one is available. | ||
const emailIdentity = findUserIdentity(user, 'email') | ||
if (emailIdentity !== undefined) { | ||
return getEmail(user) | ||
if (user.identities.email !== undefined) { | ||
return user.identities.email.id | ||
} | ||
|
||
const googleIdentity = findUserIdentity(user, 'google') | ||
if (googleIdentity !== undefined) { | ||
return `Google user ${googleIdentity.providerUserId}` | ||
if (user.identities.google !== undefined) { | ||
return `Google user ${user.identities.google.id}` | ||
} | ||
|
||
const githubIdentity = findUserIdentity(user, 'github') | ||
if (githubIdentity !== undefined) { | ||
return `GitHub user ${githubIdentity.providerUserId}` | ||
if (user.identities.github !== undefined) { | ||
return `GitHub user ${user.identities.github.id}` | ||
} | ||
|
||
const keycloakIdentity = findUserIdentity(user, 'keycloak') | ||
if (keycloakIdentity) { | ||
return `Keycloak user ${keycloakIdentity.providerUserId}` | ||
if (user.identities.keycloak !== undefined) { | ||
return `Keycloak user ${user.identities.keycloak.id}` | ||
} | ||
|
||
// If we don't know how to get the name, return null. | ||
return null | ||
} | ||
|
||
export function getProviderData(user?: User) { | ||
if (!user) { | ||
return null | ||
} | ||
|
||
const emailIdentity = findUserIdentity(user, 'email') | ||
return emailIdentity && 'isEmailVerified' in emailIdentity.providerData | ||
? emailIdentity.providerData | ||
: 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.