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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user