Replies: 2 comments 4 replies
-
Hey there, Absolutely, adding those checks to the login process is a good way to enhance security and user experience. In a typical web application, you would want to implement these checks in a way that's easy to manage and understand. Here's how you could approach it:
import React, { useState } from 'react'; const LoginPage = () => { const handleLogin = async () => { // ... rest of your component ... export default LoginPage; In this example,
Remember, this is just a basic example to get you started. Your actual implementation might vary based on your specific application structure and requirements. The key is to integrate these checks seamlessly into your login process and ensure a smooth user experience. Hope this helps! If you have more specific questions or need further assistance, feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
You can set instead a export type SessionData = {
session_id: string
user_id: string
user_company_id: string | null | undefined
}
export const authenticator = new Authenticator<SessionData>(sessionStorage, {
sessionKey: 'sessionKeyName',
})
const SESSION_EXPIRATION_TIME = 1000 * 60 * 60 * 24 * 30
authenticator.use(
new FormStrategy(async ({ form }) => {
const email = form.get('email')
const password = form.get('password')
invariant(typeof email === 'string', 'username must be a string')
invariant(email.length > 0, 'username must not be empty')
invariant(typeof password === 'string', 'password must be a string')
invariant(password.length > 0, 'password must not be empty')
const user = await verifyLogin(email, password)
if (!user) {
throw new Error('Invalid email or password')
}
const session = await insertSession(getClientWithGlobals(user.id), {
user_id: user.id,
date: new Date(Date.now() + SESSION_EXPIRATION_TIME),
})
// here I am returning all this data in the session. The only limit is the storage limit of the cookie 4Kb I think
return {
session_id: session.id,
user_id: user.id,
user_company_id: user.company_id,
}
}),
FormStrategy.name,
)
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I have some requirements to add more checks to login which look to see if the user has been inactive for x time and if they are a type of user before setting session data, I couldn't wrap my head around which part of app/routes/resources+/login.tsx would be best to add this hook.
Beta Was this translation helpful? Give feedback.
All reactions