Expose Sanitized User on the frontend (#1190)

This commit is contained in:
Filip Sodić 2023-05-04 11:47:56 +02:00 committed by GitHub
parent 3f16e92b58
commit 29889a9c37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 17 deletions

View File

@ -0,0 +1,2 @@
// todo(filip): turn into a proper import/path
export { type SanitizedUser as User } from '../../../server/src/_types/'

View File

@ -3,10 +3,10 @@ import { deserialize as superjsonDeserialize } from 'superjson'
import { useQuery } from '../queries'
import api, { handleApiError } from '../api'
import { HttpMethod } from '../types'
// todo(filip): turn into a proper import
import { type SanitizedUser as User } from '../../../server/src/_types/'
import type { User } from './types'
import { addMetadataToQuery } from '../queries/core'
export const getMe = createUserGetter()
export default function useAuth(queryFnArgs?: unknown, config?: any) {

View File

@ -102,6 +102,7 @@ waspComplexTest/.wasp/out/web-app/src/auth/helpers/user.ts
waspComplexTest/.wasp/out/web-app/src/auth/logout.js
waspComplexTest/.wasp/out/web-app/src/auth/pages/OAuthCodeExchange.jsx
waspComplexTest/.wasp/out/web-app/src/auth/pages/createAuthRequiredPage.jsx
waspComplexTest/.wasp/out/web-app/src/auth/types.ts
waspComplexTest/.wasp/out/web-app/src/auth/useAuth.ts
waspComplexTest/.wasp/out/web-app/src/config.js
waspComplexTest/.wasp/out/web-app/src/entities/index.ts

View File

@ -706,12 +706,19 @@
],
"eb3eced8b273e539f1f0d06a4f99194237e414d208136ac5ac3da6e3c52c2566"
],
[
[
"file",
"web-app/src/auth/types.ts"
],
"b6572845796b4217c142b855fc72652d5dfd67fd317b0ed5487fa70ba3d92219"
],
[
[
"file",
"web-app/src/auth/useAuth.ts"
],
"8d4051f75e47c6bfa1d44ef2ecf252e38988795c1a8b795cdf5ca3c7a1ac065d"
"f730cb58a5ebd12285b7568bec34f4e5615261580cff1727e64b5c871d784d62"
],
[
[

View File

@ -0,0 +1,2 @@
// todo(filip): turn into a proper import/path
export { type SanitizedUser as User } from '../../../server/src/_types/'

View File

@ -2,10 +2,10 @@ import { deserialize as superjsonDeserialize } from 'superjson'
import { useQuery } from '../queries'
import api, { handleApiError } from '../api'
import { HttpMethod } from '../types'
// todo(filip): turn into a proper import
import { type SanitizedUser as User } from '../../../server/src/_types/'
import type { User } from './types'
import { addMetadataToQuery } from '../queries/core'
export const getMe = createUserGetter()
export default function useAuth(queryFnArgs?: unknown, config?: any) {

View File

@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { Link } from 'react-router-dom'
import { User } from '@wasp/entities'
import { User } from '@wasp/auth/types'
import api from '@wasp/api'
async function fetchCustomRoute() {

View File

@ -26,24 +26,22 @@ import Wasp.Util ((<++>))
genAuth :: AppSpec -> Generator [FileDraft]
genAuth spec =
case maybeAuth of
Nothing -> return []
Just auth ->
sequence
[ genLogout,
[ copyTmplFile [relfile|auth/logout.js|],
copyTmplFile [relfile|auth/helpers/user.ts|],
copyTmplFile [relfile|auth/types.ts|],
genUseAuth auth,
genCreateAuthRequiredPage auth,
genUserHelpers
genCreateAuthRequiredPage auth
]
<++> genAuthForms auth
<++> genLocalAuth auth
<++> genOAuthAuth auth
<++> genEmailAuth auth
Nothing -> return []
where
maybeAuth = AS.App.auth $ snd $ getApp spec
-- | Generates file with logout function to be used by Wasp developer.
genLogout :: Generator FileDraft
genLogout = return $ C.mkTmplFd (C.asTmplFile [relfile|src/auth/logout.js|])
copyTmplFile = return . C.mkSrcTmplFd
-- | Generates HOC that handles auth for the given page.
genCreateAuthRequiredPage :: AS.Auth.Auth -> Generator FileDraft
@ -109,6 +107,3 @@ compileTmplToSamePath tmplFileInTmplSrcDir keyValuePairs =
C.mkTmplFdWithData
(asTmplFile $ [reldir|src|] </> tmplFileInTmplSrcDir)
(object keyValuePairs)
genUserHelpers :: Generator FileDraft
genUserHelpers = return $ C.mkTmplFd (C.asTmplFile [relfile|src/auth/helpers/user.ts|])