feat: Introduce useCourse and useAuth composables, and add new pages for user registration and dynamic course details.
This commit is contained in:
parent
ffd2d55e33
commit
7b22699b13
4 changed files with 7 additions and 46 deletions
|
|
@ -1,9 +1,4 @@
|
|||
// Shared global state for current user
|
||||
import type { H3Event } from 'h3'
|
||||
|
||||
|
||||
|
||||
// Types based on API responses
|
||||
interface User {
|
||||
id: number
|
||||
username: string
|
||||
|
|
@ -64,9 +59,8 @@ export const useAuth = () => {
|
|||
secure: false
|
||||
})
|
||||
|
||||
// ... (previous code)
|
||||
|
||||
// Login
|
||||
|
||||
const login = async (credentials: { email: string; password: string }) => {
|
||||
try {
|
||||
const data = await $fetch<loginResponse>(`${API_BASE_URL}/auth/login`, {
|
||||
|
|
@ -98,7 +92,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Register
|
||||
const register = async (payload: RegisterPayload) => {
|
||||
try {
|
||||
const data = await $fetch(`${API_BASE_URL}/auth/register-learner`, {
|
||||
|
|
@ -117,7 +110,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Fetch User Profile (/api/user/me)
|
||||
const fetchUserProfile = async () => {
|
||||
if (!token.value) return
|
||||
|
||||
|
|
@ -160,7 +152,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Update User Profile
|
||||
const updateUserProfile = async (payload: {
|
||||
first_name: string
|
||||
last_name: string
|
||||
|
|
@ -188,7 +179,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Request Password Reset
|
||||
const requestPasswordReset = async (email: string) => {
|
||||
try {
|
||||
await $fetch(`${API_BASE_URL}/auth/reset-request`, {
|
||||
|
|
@ -202,7 +192,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Confirm Reset Password
|
||||
const confirmResetPassword = async (payload: { token: string; password: string }) => {
|
||||
try {
|
||||
await $fetch(`${API_BASE_URL}/auth/reset-password`, {
|
||||
|
|
@ -216,7 +205,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Change Password
|
||||
const changePassword = async (payload: { oldPassword: string, newPassword: string }) => {
|
||||
if (!token.value) return { success: false, error: 'ไม่พบ Token การใช้งาน' }
|
||||
|
||||
|
|
@ -235,7 +223,6 @@ export const useAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Refresh Access Token
|
||||
const refreshAccessToken = async () => {
|
||||
if (!refreshToken.value) return false
|
||||
|
||||
|
|
@ -258,7 +245,6 @@ export const useAuth = () => {
|
|||
return false
|
||||
}
|
||||
|
||||
// Logout
|
||||
const logout = () => {
|
||||
token.value = null
|
||||
refreshToken.value = null // Clear refresh token
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
import type { H3Event } from 'h3'
|
||||
|
||||
// Types based on API responses
|
||||
export interface Course {
|
||||
id: number
|
||||
title: string | { th: string; en: string }
|
||||
|
|
@ -10,7 +7,7 @@ export interface Course {
|
|||
price: string
|
||||
is_free: boolean
|
||||
have_certificate: boolean
|
||||
status: string // 'DRAFT' | 'PUBLISHED' | ...
|
||||
status: string
|
||||
category_id: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
|
|
@ -20,10 +17,10 @@ export interface Course {
|
|||
approved_by?: number
|
||||
rejection_reason?: string
|
||||
|
||||
// Helper properties for UI (may be computed or mapped)
|
||||
|
||||
rating?: string
|
||||
lessons?: number | string
|
||||
levelType?: 'neutral' | 'warning' | 'success' // For UI badging
|
||||
levelType?: 'neutral' | 'warning' | 'success'
|
||||
|
||||
chapters?: {
|
||||
id: number
|
||||
|
|
@ -45,7 +42,7 @@ interface CourseResponse {
|
|||
}
|
||||
|
||||
export interface EnrolledCourse {
|
||||
id: number // enrollment_id
|
||||
id: number
|
||||
course_id: number
|
||||
course: Course
|
||||
status: 'ENROLLED' | 'IN_PROGRESS' | 'COMPLETED' | 'DROPPED'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue