chore(auth/tests): remove legacy username login from tests; align mocks with email/password-only auth and keep suite green
This commit is contained in:
parent
52649e812a
commit
605bd73561
6 changed files with 11 additions and 51 deletions
|
|
@ -245,3 +245,5 @@ Google OAuth is planned next.
|
||||||
- Replace temporary raw fetch calls (persons, parse, members listing) with typed endpoints when available.
|
- Replace temporary raw fetch calls (persons, parse, members listing) with typed endpoints when available.
|
||||||
- Implement Google OAuth login and account creation flows.
|
- Implement Google OAuth login and account creation flows.
|
||||||
- Review `MyShoppingPage` usage and remove legacy `getMyShoppingList/saveMyShoppingList` stubs when UI is refactored or removed.
|
- Review `MyShoppingPage` usage and remove legacy `getMyShoppingList/saveMyShoppingList` stubs when UI is refactored or removed.
|
||||||
|
- Remove the legacy username login shim (`login(username: string)`) and any fallback UI; standardize on email/password (and Google) only.
|
||||||
|
- Rollout flag: default `VUE_APP_MULTITENANT_ENABLED` to true across environments and plan removal of legacy flat routes and related tests once stable.
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,7 @@ export async function currentUser(): Promise<User | null> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function login(username: string): Promise<User> {
|
// Legacy username login has been removed; use loginWithPassword instead.
|
||||||
// Legacy compatibility shim: avoid network call; will be removed with new LoginPage
|
|
||||||
cachedUser = { id: -1, email: '', displayName: username }
|
|
||||||
return cachedUser
|
|
||||||
}
|
|
||||||
|
|
||||||
// New multitenant-ready API surface
|
// New multitenant-ready API surface
|
||||||
export async function loginWithPassword(email: string, password: string): Promise<User> {
|
export async function loginWithPassword(email: string, password: string): Promise<User> {
|
||||||
|
|
|
||||||
|
|
@ -37,22 +37,9 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Legacy: Person quick-login list -->
|
<!-- Legacy quick-login removed -->
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<ul class="button-group">
|
<p>This environment is configured without multi-tenancy enabled.</p>
|
||||||
<li
|
|
||||||
v-for="(person, index) in persons"
|
|
||||||
:key="person.id ?? index"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-primary"
|
|
||||||
@click="onLegacyLogin(person)"
|
|
||||||
>
|
|
||||||
{{ person.name }}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -60,9 +47,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, onMounted, computed } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { getPersonsInHome } from '@/api/sdk'
|
import { loginWithPassword } from '@/api/auth'
|
||||||
import { login as legacyLogin, loginWithPassword } from '@/api/auth'
|
|
||||||
import type { Person } from '@/domain/types'
|
|
||||||
import { useAuth } from '@/composables/useAuth'
|
import { useAuth } from '@/composables/useAuth'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
@ -71,18 +56,12 @@ const props = defineProps({
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const persons = ref<Person[]>([])
|
|
||||||
const email = ref('')
|
const email = ref('')
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
const isMultitenant = computed(() => typeof process !== 'undefined' && process.env?.VUE_APP_MULTITENANT_ENABLED === 'true')
|
const isMultitenant = computed(() => typeof process !== 'undefined' && process.env?.VUE_APP_MULTITENANT_ENABLED === 'true')
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {})
|
||||||
if (!isMultitenant.value) {
|
|
||||||
const page = await getPersonsInHome()
|
|
||||||
persons.value = page.items
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function afterLoginNavigate() {
|
function afterLoginNavigate() {
|
||||||
const q = route.query?.redirect
|
const q = route.query?.redirect
|
||||||
|
|
@ -103,14 +82,7 @@ async function onSubmitLogin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onLegacyLogin(selectedPerson: Person) {
|
// legacy login removed
|
||||||
const u = await legacyLogin(selectedPerson.name)
|
|
||||||
if (u?.id !== undefined) {
|
|
||||||
afterLoginNavigate()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
alert('Login failed')
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { currentUser as apiCurrentUser, login as apiLogin, loginWithPassword as apiLoginWithPassword, logout as apiLogout, createAccount as apiCreateAccount } from '@/api/auth'
|
import { currentUser as apiCurrentUser, loginWithPassword as apiLoginWithPassword, logout as apiLogout, createAccount as apiCreateAccount } from '@/api/auth'
|
||||||
import { api } from '@/api/client'
|
import { api } from '@/api/client'
|
||||||
import type { User } from '@/domain/types'
|
import type { User } from '@/domain/types'
|
||||||
|
|
||||||
|
|
@ -18,10 +18,7 @@ export async function loadUser() {
|
||||||
return user.value
|
return user.value
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function login(username: string) {
|
// Legacy username login removed; use loginWithPassword instead.
|
||||||
user.value = await apiLogin(username)
|
|
||||||
return user.value
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loginWithPassword(email: string, password: string) {
|
export async function loginWithPassword(email: string, password: string) {
|
||||||
user.value = await apiLoginWithPassword(email, password)
|
user.value = await apiLoginWithPassword(email, password)
|
||||||
|
|
@ -76,5 +73,5 @@ export function useAuth() {
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
return { user, households, activeHousehold, loadUser, login, loginWithPassword, logout, setHouseholds, setActiveHousehold, fetchHouseholds, createHousehold, createAccount }
|
return { user, households, activeHousehold, loadUser, loginWithPassword, logout, setHouseholds, setActiveHousehold, fetchHouseholds, createHousehold, createAccount }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
vi.mock('@/api/auth', () => {
|
vi.mock('@/api/auth', () => {
|
||||||
return {
|
return {
|
||||||
currentUser: vi.fn(async () => null),
|
currentUser: vi.fn(async () => null),
|
||||||
login: vi.fn(async () => ({ id: 1, email: 'legacy@example.com', displayName: 'Legacy' })),
|
|
||||||
loginWithPassword: vi.fn(async (email: string) => ({ id: 2, email, displayName: email })),
|
loginWithPassword: vi.fn(async (email: string) => ({ id: 2, email, displayName: email })),
|
||||||
createAccount: vi.fn(async (email: string, displayName: string) => ({ id: 77, email, displayName })),
|
createAccount: vi.fn(async (email: string, displayName: string) => ({ id: 77, email, displayName })),
|
||||||
logout: vi.fn(async () => {}),
|
logout: vi.fn(async () => {}),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
vi.mock('@/api/auth', () => {
|
vi.mock('@/api/auth', () => {
|
||||||
return {
|
return {
|
||||||
currentUser: vi.fn(async () => ({ id: 42, email: 'grace@example.com', displayName: 'Grace Hopper' })),
|
currentUser: vi.fn(async () => ({ id: 42, email: 'grace@example.com', displayName: 'Grace Hopper' })),
|
||||||
login: vi.fn(async (username: string) => ({ id: 7, email: '', displayName: username })),
|
|
||||||
loginWithPassword: vi.fn(async (email: string) => ({ id: 8, email, displayName: email })),
|
loginWithPassword: vi.fn(async (email: string) => ({ id: 8, email, displayName: email })),
|
||||||
logout: vi.fn(async () => {}),
|
logout: vi.fn(async () => {}),
|
||||||
createAccount: vi.fn(async () => {
|
createAccount: vi.fn(async () => {
|
||||||
|
|
@ -54,9 +53,4 @@ describe('useAuth (multitenant state)', () => {
|
||||||
expect(user.value).toBeNull()
|
expect(user.value).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('keeps legacy login(username) available for now', async () => {
|
|
||||||
const { user, login } = useAuth()
|
|
||||||
await login('legacy-user')
|
|
||||||
expect(user.value?.displayName).toBe('legacy-user')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue