W
Wasp3d ago
Noah

Examples of creating session with wasp 0.16.0

I want to create a user session via Wasp's auth hooks, but I can't find any good examples of using the existing auth utils. In old code snippets I see references to createSession but I can't find that anymore. Any suggested reading?
4 Replies
kapa.ai
kapa.ai3d ago
Hi @Noah. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, I can offer some information about sessions in Wasp, but I don't have specific examples for creating a user session using auth hooks in Wasp 0.16.0. However, I can provide some relevant details about how Wasp handles sessions: 1. Wasp uses sessions for authentication and keeping track of logged-in users. The sessions are managed using the Lucia Auth v3 library under the hood. 2. When users log in, Wasp automatically creates a session for them and stores it in the database. The session is then sent to the client and stored in localStorage. 3. Wasp provides a useAuth hook that you can use in client components to access the current user's session information. Auth Overview - Sessions explains: "Wasp's auth uses sessions to keep track of the logged-in user. The session is stored in localStorage on the client and in the database on the server. Under the hood, Wasp uses the excellent Lucia Auth v3 library for session management." For more details on using authentication in Wasp, you might want to check out the Auth Overview and Auth UI documentation pages. Unfortunately, I don't have specific information about createSession or examples of creating sessions manually in Wasp 0.16.0. It seems that Wasp might handle session creation automatically when users log in, but without more recent documentation or examples, I can't provide a definitive answer on how to create sessions manually in the current version. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Noah, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Noah
NoahOP3d ago
@kapa.ai do you have any gists or code snippets using auth utilities?
kapa.ai
kapa.ai3d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources provided, I can share some code snippets that demonstrate the usage of auth utilities in Wasp. Here are a few examples: 1. Using the LoginForm component:
import { LoginForm } from 'wasp/client/auth'

export function LoginPage() {
return <LoginForm />
}
import { LoginForm } from 'wasp/client/auth'

export function LoginPage() {
return <LoginForm />
}
This snippet is from the Auth UI Components documentation. 2. Checking authentication in a query:
import { HttpError } from 'wasp/server'

export const getTasks = async (args, context) => {
if (!context.user) {
throw new HttpError(401)
}
return context.entities.Task.findMany({
where: { user: { id: context.user.id } },
orderBy: { id: 'asc' },
})
}
import { HttpError } from 'wasp/server'

export const getTasks = async (args, context) => {
if (!context.user) {
throw new HttpError(401)
}
return context.entities.Task.findMany({
where: { user: { id: context.user.id } },
orderBy: { id: 'asc' },
})
}
This example is from the Tutorial section on updating operations to check authentication. 3. Configuring auth in the main Wasp file:
app myApp {
wasp: {
version: "^0.13.0"
},
title: "My App",
auth: {
userEntity: User,
methods: {
usernameAndPassword: {},
},
onAuthFailedRedirectTo: "/login"
}
}
app myApp {
wasp: {
version: "^0.13.0"
},
title: "My App",
auth: {
userEntity: User,
methods: {
usernameAndPassword: {},
},
onAuthFailedRedirectTo: "/login"
}
}
This configuration snippet is from the Username & Password Authentication documentation. These snippets demonstrate how to use some of Wasp's auth utilities, including the LoginForm component, checking for authenticated users in operations, and configuring auth in the main Wasp file. However, it's important to note that these examples might not be specific to version 0.16.0, as the knowledge sources don't provide version-specific information for that particular version. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Noah, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Noah
NoahOP3d ago
Ill look at the wasp source there it is import { createSession } from 'wasp/auth/session'

Did you find this page helpful?