Implement direct login functionality with email and password

- Update login API to support direct authentication via email and password, removing the OAuth2 redirect flow.
- Modify LoginForm component to include password field and validation.
- Refactor useAuth composable to handle login with both email and password.
- Remove unnecessary OAuth2 callback handler and PKCE utilities.
- Update relevant documentation and error handling for the new login method.
This commit is contained in:
Bastian Masanek
2025-10-31 14:27:38 +01:00
parent e71316dfe7
commit 7c7c4fcb6f
8 changed files with 178 additions and 268 deletions

View File

@@ -13,19 +13,26 @@ export function useAuth() {
const { loggedIn, user, clear, fetch } = useUserSession()
/**
* Login with email
* Initiates OAuth2 flow
* Login with email and password
* Direct authentication via Cidaas API (no redirect)
*/
async function login(email: string) {
async function login(email: string, password: string) {
try {
// Call login endpoint to get redirect URL
const { redirectUrl } = await $fetch('/api/auth/login', {
// Call login endpoint - creates session directly
await $fetch('/api/auth/login', {
method: 'POST',
body: { email },
body: { email, password },
})
// Redirect to Cidaas
navigateTo(redirectUrl, { external: true })
// Refresh user session
await fetch()
// Redirect to homepage or saved destination
const redirectAfterLogin = useCookie('redirect_after_login')
const destination = redirectAfterLogin.value || '/'
redirectAfterLogin.value = null // Clear cookie
navigateTo(destination)
} catch (error) {
console.error('Login failed:', error)
throw error