diff --git a/waspc/data/Generator/templates/sdk/auth/index.ts b/waspc/data/Generator/templates/sdk/auth/index.ts index 354fbe542a..56d03e4d89 100644 --- a/waspc/data/Generator/templates/sdk/auth/index.ts +++ b/waspc/data/Generator/templates/sdk/auth/index.ts @@ -1 +1,7 @@ export { defineUserSignupFields } from './providers/types.js'; + +// PUBLIC +export type { AuthUser } from '../server/_types' + +// PUBLIC +export { getEmail, getUsername, getFirstProviderUserId, findUserIdentity } from './user.js' diff --git a/waspc/data/Generator/templates/sdk/auth/session.ts b/waspc/data/Generator/templates/sdk/auth/session.ts index 487dca2046..96d8cfdf69 100644 --- a/waspc/data/Generator/templates/sdk/auth/session.ts +++ b/waspc/data/Generator/templates/sdk/auth/session.ts @@ -2,7 +2,7 @@ import { Request as ExpressRequest } from "express"; import { type {= userEntityUpper =} } from "wasp/entities" -import { type SanitizedUser } from 'wasp/server/_types' +import { type AuthUser } from 'wasp/server/_types' import { auth } from "./lucia.js"; import type { Session } from "lucia"; @@ -19,7 +19,7 @@ export async function createSession(authId: string): Promise { } export async function getSessionAndUserFromBearerToken(req: ExpressRequest): Promise<{ - user: SanitizedUser | null, + user: AuthUser | null, session: Session | null, }> { const authorizationHeader = req.headers["authorization"]; @@ -43,7 +43,7 @@ export async function getSessionAndUserFromBearerToken(req: ExpressRequest): Pro } export async function getSessionAndUserFromSessionId(sessionId: string): Promise<{ - user: SanitizedUser | null, + user: AuthUser | null, session: Session | null, }> { const { session, user: authEntity } = await auth.validateSession(sessionId); @@ -61,7 +61,7 @@ export async function getSessionAndUserFromSessionId(sessionId: string): Promise } } -async function getUser(userId: {= userEntityUpper =}['id']): Promise { +async function getUser(userId: {= userEntityUpper =}['id']): Promise { const user = await prisma.{= userEntityLower =} .findUnique({ where: { id: userId }, diff --git a/waspc/data/Generator/templates/sdk/auth/types.ts b/waspc/data/Generator/templates/sdk/auth/types.ts index f9f079a57a..b90fb05824 100644 --- a/waspc/data/Generator/templates/sdk/auth/types.ts +++ b/waspc/data/Generator/templates/sdk/auth/types.ts @@ -1,2 +1,2 @@ // todo(filip): turn into a proper import/path -export type { SanitizedUser as User, ProviderName, DeserializedAuthIdentity } from 'wasp/server/_types/' +export type { AuthUser, ProviderName, DeserializedAuthIdentity } from 'wasp/server/_types/' diff --git a/waspc/data/Generator/templates/sdk/auth/useAuth.ts b/waspc/data/Generator/templates/sdk/auth/useAuth.ts index bf2d7e63e2..c7b02273cf 100644 --- a/waspc/data/Generator/templates/sdk/auth/useAuth.ts +++ b/waspc/data/Generator/templates/sdk/auth/useAuth.ts @@ -3,7 +3,7 @@ import { deserialize as superjsonDeserialize } from 'superjson' import { useQuery } from 'wasp/rpc' import { api, handleApiError } from 'wasp/client/api' import { HttpMethod } from 'wasp/types' -import type { User } from './types' +import type { AuthUser } from './types' import { addMetadataToQuery } from 'wasp/rpc/queries' export const getMe = createUserGetter() @@ -15,7 +15,7 @@ export default function useAuth(queryFnArgs?: unknown, config?: any) { function createUserGetter() { const getMeRelativePath = 'auth/me' const getMeRoute = { method: HttpMethod.Get, path: `/${getMeRelativePath}` } - async function getMe(): Promise { + async function getMe(): Promise { try { const response = await api.get(getMeRoute.path) diff --git a/waspc/data/Generator/templates/sdk/auth/user.ts b/waspc/data/Generator/templates/sdk/auth/user.ts index a7ac86827e..0de50de6d0 100644 --- a/waspc/data/Generator/templates/sdk/auth/user.ts +++ b/waspc/data/Generator/templates/sdk/auth/user.ts @@ -1,14 +1,14 @@ -import type { User, ProviderName, DeserializedAuthIdentity } from './types' +import type { AuthUser, ProviderName, DeserializedAuthIdentity } from './types' -export function getEmail(user: User): string | null { +export function getEmail(user: AuthUser): string | null { return findUserIdentity(user, "email")?.providerUserId ?? null; } -export function getUsername(user: User): string | null { +export function getUsername(user: AuthUser): string | null { return findUserIdentity(user, "username")?.providerUserId ?? null; } -export function getFirstProviderUserId(user?: User): string | null { +export function getFirstProviderUserId(user?: AuthUser): string | null { if (!user || !user.auth || !user.auth.identities || user.auth.identities.length === 0) { return null; } @@ -16,7 +16,7 @@ export function getFirstProviderUserId(user?: User): string | null { return user.auth.identities[0].providerUserId ?? null; } -export function findUserIdentity(user: User, providerName: ProviderName): DeserializedAuthIdentity | undefined { +export function findUserIdentity(user: AuthUser, providerName: ProviderName): DeserializedAuthIdentity | undefined { return user.auth.identities.find( (identity) => identity.providerName === providerName ); diff --git a/waspc/data/Generator/templates/sdk/package.json b/waspc/data/Generator/templates/sdk/package.json index 9a98d56f13..946db6b097 100644 --- a/waspc/data/Generator/templates/sdk/package.json +++ b/waspc/data/Generator/templates/sdk/package.json @@ -37,10 +37,6 @@ "./rpc/queryClient": "./dist/rpc/queryClient.js", {=! Used by users, documented. =} "./types": "./dist/types/index.js", - {=! Used by user, documented. =} - "./auth": "./dist/auth/index.js", - {=! Used by users, documented. =} - "./auth/types": "./dist/auth/types.js", {=! Used by users, documented. =} "./auth/login": "./dist/auth/login.js", {=! Used by users, documented. =} @@ -50,8 +46,6 @@ {=! Used by users, documented. =} "./auth/useAuth": "./dist/auth/useAuth.js", {=! Used by users, documented. =} - "./auth/user": "./dist/auth/user.js", - {=! Used by users, documented. =} "./auth/email": "./dist/auth/email/index.js", {=! Used by our code, uncodumented (but accessible) for users. =} "./auth/helpers/user": "./dist/auth/helpers/user.js", @@ -150,7 +144,8 @@ "./server/api": "./dist/server/api/index.js", {=! Public: { api } =} {=! Private: [sdk] =} - "./client/api": "./dist/api/index.js" + "./client/api": "./dist/api/index.js", + "./auth": "./dist/auth/index.js" }, {=! TypeScript doesn't care about the redirects we define above in "exports" field; those diff --git a/waspc/data/Generator/templates/sdk/server/_types/index.ts b/waspc/data/Generator/templates/sdk/server/_types/index.ts index c00ecce15e..a1b438e2af 100644 --- a/waspc/data/Generator/templates/sdk/server/_types/index.ts +++ b/waspc/data/Generator/templates/sdk/server/_types/index.ts @@ -86,7 +86,7 @@ type Context = Expand<{ }> {=# isAuthEnabled =} -type ContextWithUser = Expand & { user?: SanitizedUser }> +type ContextWithUser = Expand & { user?: AuthUser }> // TODO: This type must match the logic in auth/session.js (if we remove the // password field from the object there, we must do the same here). Ideally, @@ -97,7 +97,7 @@ export type DeserializedAuthIdentity = Expand | Omit | OAuthProviderData }> -export type SanitizedUser = {= userEntityName =} & { +export type AuthUser = {= userEntityName =} & { {= authFieldOnUserEntityName =}: {= authEntityName =} & { {= identitiesFieldOnAuthEntityName =}: DeserializedAuthIdentity[] } | null diff --git a/waspc/data/Generator/templates/sdk/server/utils.ts b/waspc/data/Generator/templates/sdk/server/utils.ts index 6ca262decd..9bae69db17 100644 --- a/waspc/data/Generator/templates/sdk/server/utils.ts +++ b/waspc/data/Generator/templates/sdk/server/utils.ts @@ -7,12 +7,12 @@ import { dirname } from 'path' import { fileURLToPath } from 'url' {=# isAuthEnabled =} -import { type SanitizedUser } from 'wasp/server/_types/index.js' +import { type AuthUser } from 'wasp/auth' {=/ isAuthEnabled =} type RequestWithExtraFields = Request & { {=# isAuthEnabled =} - user?: SanitizedUser; + user?: AuthUser; sessionId?: string; {=/ isAuthEnabled =} } diff --git a/waspc/data/Generator/templates/sdk/server/webSocket/index.ts b/waspc/data/Generator/templates/sdk/server/webSocket/index.ts index f40a15d019..82a044185b 100644 --- a/waspc/data/Generator/templates/sdk/server/webSocket/index.ts +++ b/waspc/data/Generator/templates/sdk/server/webSocket/index.ts @@ -5,7 +5,7 @@ import { EventsMap, DefaultEventsMap } from '@socket.io/component-emitter' import { prisma } from 'wasp/server' {=# isAuthEnabled =} -import { type SanitizedUser } from 'wasp/server/_types/index.js' +import { type AuthUser } from 'wasp/auth' {=/ isAuthEnabled =} {=& userWebSocketFn.importStatement =} @@ -33,7 +33,7 @@ export type WebSocketDefinition< export interface WaspSocketData { {=# isAuthEnabled =} - user?: SanitizedUser + user?: AuthUser {=/ isAuthEnabled =} } diff --git a/waspc/data/Generator/templates/server/src/routes/apis/index.ts b/waspc/data/Generator/templates/server/src/routes/apis/index.ts index 6a1b1dcd00..1e6939c621 100644 --- a/waspc/data/Generator/templates/server/src/routes/apis/index.ts +++ b/waspc/data/Generator/templates/server/src/routes/apis/index.ts @@ -5,7 +5,7 @@ import { handleRejection } from 'wasp/server/utils' import { MiddlewareConfigFn, globalMiddlewareConfigForExpress } from '../../middleware/index.js' {=# isAuthEnabled =} import auth from 'wasp/core/auth' -import { type SanitizedUser } from 'wasp/server/_types' +import { type AuthUser } from 'wasp/auth' {=/ isAuthEnabled =} {=# apiNamespaces =} @@ -45,7 +45,7 @@ router.{= routeMethod =}( {=/ usesAuth =} handleRejection( ( - req: Parameters[0]{=# usesAuth =} & { user: SanitizedUser }{=/ usesAuth =}, + req: Parameters[0]{=# usesAuth =} & { user: AuthUser }{=/ usesAuth =}, res: Parameters[1], ) => { const context = { diff --git a/waspc/data/Generator/templates/server/src/utils.ts b/waspc/data/Generator/templates/server/src/utils.ts index 6ca262decd..9bae69db17 100644 --- a/waspc/data/Generator/templates/server/src/utils.ts +++ b/waspc/data/Generator/templates/server/src/utils.ts @@ -7,12 +7,12 @@ import { dirname } from 'path' import { fileURLToPath } from 'url' {=# isAuthEnabled =} -import { type SanitizedUser } from 'wasp/server/_types/index.js' +import { type AuthUser } from 'wasp/auth' {=/ isAuthEnabled =} type RequestWithExtraFields = Request & { {=# isAuthEnabled =} - user?: SanitizedUser; + user?: AuthUser; sessionId?: string; {=/ isAuthEnabled =} } diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/api/index.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/api/index.ts index 971f010160..d066bd5448 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/api/index.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/api/index.ts @@ -4,7 +4,8 @@ import config from 'wasp/core/config' import { storage } from 'wasp/core/storage' import { apiEventsEmitter } from './events.js' -const api = axios.create({ +// PUBLIC API +export const api = axios.create({ baseURL: config.apiUrl, }) @@ -12,22 +13,26 @@ const WASP_APP_AUTH_SESSION_ID_NAME = 'sessionId' let waspAppAuthSessionId = storage.get(WASP_APP_AUTH_SESSION_ID_NAME) as string | undefined +// PRIVATE API (sdk) export function setSessionId(sessionId: string): void { waspAppAuthSessionId = sessionId storage.set(WASP_APP_AUTH_SESSION_ID_NAME, sessionId) apiEventsEmitter.emit('sessionId.set') } +// PRIVATE API (sdk) export function getSessionId(): string | undefined { return waspAppAuthSessionId } +// PRIVATE API (sdk) export function clearSessionId(): void { waspAppAuthSessionId = undefined storage.remove(WASP_APP_AUTH_SESSION_ID_NAME) apiEventsEmitter.emit('sessionId.clear') } +// PRIVATE API (sdk) export function removeLocalUserData(): void { waspAppAuthSessionId = undefined storage.clear() @@ -66,6 +71,7 @@ window.addEventListener('storage', (event) => { } }) +// PRIVATE API (sdk) /** * Takes an error returned by the app's API (as returned by axios), and transforms into a more * standard format to be further used by the client. It is also assumed that given API @@ -100,5 +106,3 @@ class WaspHttpError extends Error { this.data = data } } - -export default api diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/helpers/user.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/helpers/user.ts index 498f2588a8..259a4c34b5 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/helpers/user.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/helpers/user.ts @@ -1,4 +1,4 @@ -import { setSessionId } from 'wasp/api' +import { setSessionId } from 'wasp/client/api' import { invalidateAndRemoveQueries } from 'wasp/operations/resources' export async function initSession(sessionId: string): Promise { diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/logout.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/logout.ts index cc41b6989c..7f40b0cbf6 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/logout.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/logout.ts @@ -1,4 +1,4 @@ -import api, { removeLocalUserData } from 'wasp/api' +import { api, removeLocalUserData } from 'wasp/client/api' import { invalidateAndRemoveQueries } from 'wasp/operations/resources' export default async function logout(): Promise { diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/types.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/types.ts index f9f079a57a..b90fb05824 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/types.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/types.ts @@ -1,2 +1,2 @@ // todo(filip): turn into a proper import/path -export type { SanitizedUser as User, ProviderName, DeserializedAuthIdentity } from 'wasp/server/_types/' +export type { AuthUser, ProviderName, DeserializedAuthIdentity } from 'wasp/server/_types/' diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/useAuth.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/useAuth.ts index 4f0b835913..47a6293879 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/useAuth.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/useAuth.ts @@ -1,8 +1,8 @@ import { deserialize as superjsonDeserialize } from 'superjson' import { useQuery } from 'wasp/rpc' -import api, { handleApiError } from 'wasp/api' +import { api, handleApiError } from 'wasp/client/api' import { HttpMethod } from 'wasp/types' -import type { User } from './types' +import type { AuthUser } from './types' import { addMetadataToQuery } from 'wasp/rpc/queries' export const getMe = createUserGetter() @@ -14,7 +14,7 @@ export default function useAuth(queryFnArgs?: unknown, config?: any) { function createUserGetter() { const getMeRelativePath = 'auth/me' const getMeRoute = { method: HttpMethod.Get, path: `/${getMeRelativePath}` } - async function getMe(): Promise { + async function getMe(): Promise { try { const response = await api.get(getMeRoute.path) diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/user.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/user.ts index a7ac86827e..0de50de6d0 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/user.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/user.ts @@ -1,14 +1,14 @@ -import type { User, ProviderName, DeserializedAuthIdentity } from './types' +import type { AuthUser, ProviderName, DeserializedAuthIdentity } from './types' -export function getEmail(user: User): string | null { +export function getEmail(user: AuthUser): string | null { return findUserIdentity(user, "email")?.providerUserId ?? null; } -export function getUsername(user: User): string | null { +export function getUsername(user: AuthUser): string | null { return findUserIdentity(user, "username")?.providerUserId ?? null; } -export function getFirstProviderUserId(user?: User): string | null { +export function getFirstProviderUserId(user?: AuthUser): string | null { if (!user || !user.auth || !user.auth.identities || user.auth.identities.length === 0) { return null; } @@ -16,7 +16,7 @@ export function getFirstProviderUserId(user?: User): string | null { return user.auth.identities[0].providerUserId ?? null; } -export function findUserIdentity(user: User, providerName: ProviderName): DeserializedAuthIdentity | undefined { +export function findUserIdentity(user: AuthUser, providerName: ProviderName): DeserializedAuthIdentity | undefined { return user.auth.identities.find( (identity) => identity.providerName === providerName ); diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/utils.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/utils.ts index c30b07109f..4f08b8d552 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/utils.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/auth/utils.ts @@ -2,7 +2,7 @@ import { hashPassword } from './password.js' import { verify } from './jwt.js' import AuthError from 'wasp/core/AuthError' import HttpError from 'wasp/core/HttpError' -import prisma from 'wasp/server/dbClient' +import { prisma } from 'wasp/server' import { sleep } from 'wasp/server/utils' import { type User, diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/operations/index.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/operations/index.ts index 1da917cb2c..8ef076ee1f 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/operations/index.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/operations/index.ts @@ -1,4 +1,4 @@ -import api, { handleApiError } from 'wasp/api' +import { api, handleApiError } from 'wasp/client/api' import { HttpMethod } from 'wasp/types' import { serialize as superjsonSerialize, diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/package.json b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/package.json index 967b1d43de..8e954a8490 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/package.json +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/package.json @@ -21,13 +21,10 @@ "./rpc/actions/core": "./dist/rpc/actions/core.js", "./rpc/queryClient": "./dist/rpc/queryClient.js", "./types": "./dist/types/index.js", - "./auth": "./dist/auth/index.js", - "./auth/types": "./dist/auth/types.js", "./auth/login": "./dist/auth/login.js", "./auth/logout": "./dist/auth/logout.js", "./auth/signup": "./dist/auth/signup.js", "./auth/useAuth": "./dist/auth/useAuth.js", - "./auth/user": "./dist/auth/user.js", "./auth/email": "./dist/auth/email/index.js", "./auth/helpers/user": "./dist/auth/helpers/user.js", "./auth/session": "./dist/auth/session.js", @@ -44,7 +41,6 @@ "./auth/forms/internal/Form": "./dist/auth/forms/internal/Form.jsx", "./auth/helpers/*": "./dist/auth/helpers/*.jsx", "./auth/pages/createAuthRequiredPage": "./dist/auth/pages/createAuthRequiredPage.jsx", - "./api": "./dist/api/index.js", "./api/events": "./dist/api/events.js", "./operations": "./dist/operations/index.js", "./ext-src/*": "./dist/ext-src/*.js", @@ -52,9 +48,6 @@ "./universal/url": "./dist/universal/url.js", "./universal/types": "./dist/universal/types.js", "./universal/validators": "./dist/universal/validators.js", - "./server/dbClient": "./dist/server/dbClient.js", - "./server/config": "./dist/server/config.js", - "./server/types": "./dist/server/types/index.js", "./server/middleware": "./dist/server/middleware/index.js", "./server/utils": "./dist/server/utils.js", "./server/actions": "./dist/server/actions/index.js", @@ -73,13 +66,25 @@ "./router": "./dist/router/index.js", "./server/webSocket": "./dist/server/webSocket/index.js", "./webSocket": "./dist/webSocket/index.js", - "./webSocket/WebSocketProvider": "./dist/webSocket/WebSocketProvider.jsx" + "./webSocket/WebSocketProvider": "./dist/webSocket/WebSocketProvider.jsx", + + "./server/types": "./dist/server/types/index.js", + + "./server": "./dist/server/index.js", + "./server/api": "./dist/server/api/index.js", + "./client/api": "./dist/api/index.js", + "./auth": "./dist/auth/index.js" + }, + "typesVersions": { + "*": { + "client/api": ["api/index.ts"] + } }, "license": "ISC", "include": [ "src/**/*" ], - "dependencies": {"@prisma/client": "4.16.2", + "dependencies": {"@prisma/client": "4.16.2", "prisma": "4.16.2", "@tanstack/react-query": "^4.29.0", "axios": "^1.4.0", @@ -106,6 +111,6 @@ "@testing-library/jest-dom": "^6.3.0", "msw": "^1.1.0" }, - "devDependencies": {"@tsconfig/node18": "latest" + "devDependencies": {"@tsconfig/node18": "latest" } } diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/_types/index.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/_types/index.ts index 141cc718a1..fa27d07d00 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/_types/index.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/_types/index.ts @@ -1,7 +1,7 @@ import { type Expand } from 'wasp/universal/types'; import { type Request, type Response } from 'express' import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core' -import prisma from "wasp/server/dbClient" +import { prisma } from 'wasp/server' import { type User, type Auth, @@ -79,7 +79,7 @@ type Context = Expand<{ entities: Expand> }> -type ContextWithUser = Expand & { user?: SanitizedUser }> +type ContextWithUser = Expand & { user?: AuthUser }> // TODO: This type must match the logic in auth/session.js (if we remove the // password field from the object there, we must do the same here). Ideally, @@ -90,7 +90,7 @@ export type DeserializedAuthIdentity = Expand providerData: Omit | Omit | OAuthProviderData }> -export type SanitizedUser = User & { +export type AuthUser = User & { auth: Auth & { identities: DeserializedAuthIdentity[] } | null diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/actions/index.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/actions/index.ts index 9078c1d3c0..54c224ba2e 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/actions/index.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/actions/index.ts @@ -1,4 +1,4 @@ -import prisma from 'wasp/server/dbClient' +import { prisma } from 'wasp/server' import { createTask as createTask_ext } from 'wasp/ext-src/task/actions.js' import { updateTask as updateTask_ext } from 'wasp/ext-src/task/actions.js' diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/queries/index.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/queries/index.ts index d6fae4f9e1..cbfb76d351 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/queries/index.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/queries/index.ts @@ -1,4 +1,4 @@ -import prisma from 'wasp/server/dbClient' +import { prisma } from 'wasp/server' import { getTasks as getTasks_ext } from 'wasp/ext-src/task/queries.js' diff --git a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/utils.ts b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/utils.ts index aa07513822..d7fe314996 100644 --- a/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/utils.ts +++ b/waspc/examples/todo-typescript/.wasp/out/sdk/wasp/server/utils.ts @@ -5,10 +5,10 @@ import { readdir } from 'fs' import { dirname } from 'path' import { fileURLToPath } from 'url' -import { type SanitizedUser } from 'wasp/server/_types/index.js' +import { type AuthUser } from 'wasp/auth' type RequestWithExtraFields = Request & { - user?: SanitizedUser; + user?: AuthUser; sessionId?: string; } diff --git a/waspc/examples/todo-typescript/src/MainPage.tsx b/waspc/examples/todo-typescript/src/MainPage.tsx index 582eb2527d..9e89cbf449 100644 --- a/waspc/examples/todo-typescript/src/MainPage.tsx +++ b/waspc/examples/todo-typescript/src/MainPage.tsx @@ -11,8 +11,7 @@ import { } from 'wasp/rpc/actions' import waspLogo from './waspLogo.png' import type { Task } from 'wasp/entities' -import type { User } from 'wasp/auth/types' -import { getFirstProviderUserId } from 'wasp/auth/user' +import { AuthUser, getFirstProviderUserId } from 'wasp/auth' import { Link } from 'react-router-dom' import { Tasks } from 'wasp/crud/Tasks' // import login from 'wasp/auth/login' @@ -20,7 +19,7 @@ import { Tasks } from 'wasp/crud/Tasks' import useAuth from 'wasp/auth/useAuth' import { Todo } from './Todo' -export const MainPage = ({ user }: { user: User }) => { +export const MainPage = ({ user }: { user: AuthUser }) => { const { data: tasks, isLoading, error } = useQuery(getTasks) const { data: userAgain } = useAuth() diff --git a/waspc/examples/todo-typescript/src/websocket/index.ts b/waspc/examples/todo-typescript/src/websocket/index.ts index 502856a824..8640fd3dc9 100644 --- a/waspc/examples/todo-typescript/src/websocket/index.ts +++ b/waspc/examples/todo-typescript/src/websocket/index.ts @@ -1,26 +1,26 @@ -import { WebSocketDefinition } from "wasp/server/webSocket"; -import { getFirstProviderUserId } from "wasp/auth/user"; +import { WebSocketDefinition } from 'wasp/server/webSocket' +import { getFirstProviderUserId } from 'wasp/auth' export const webSocketFn: WebSocketDefinition< ClientToServerEvents, ServerToClientEvents, InterServerEvents > = (io, context) => { - io.on("connection", (socket) => { - const username = getFirstProviderUserId(socket.data.user) ?? "Unknown"; - console.log("a user connected: ", username); + io.on('connection', (socket) => { + const username = getFirstProviderUserId(socket.data.user) ?? 'Unknown' + console.log('a user connected: ', username) - socket.on("chatMessage", async (msg) => { - console.log("message: ", msg); - io.emit("chatMessage", { id: "random", username, text: msg }); - }); - }); -}; + socket.on('chatMessage', async (msg) => { + console.log('message: ', msg) + io.emit('chatMessage', { id: 'random', username, text: msg }) + }) + }) +} interface ServerToClientEvents { - chatMessage: (msg: { id: string; username: string; text: string }) => void; + chatMessage: (msg: { id: string; username: string; text: string }) => void } interface ClientToServerEvents { - chatMessage: (msg: string) => void; + chatMessage: (msg: string) => void } interface InterServerEvents {}