From 2f7ced59617af9076a8135a40ef9c505a17c46fe Mon Sep 17 00:00:00 2001 From: Nyavokevin <42602932+nyavokevin@users.noreply.github.com> Date: Mon, 6 Oct 2025 18:38:16 +0300 Subject: [PATCH] auth front and back --- thanasoft-back/app/Models/User.php | 3 +- thanasoft-back/bootstrap/app.php | 1 + thanasoft-back/composer.json | 3 +- thanasoft-back/composer.lock | 66 +- thanasoft-back/config/cors.php | 28 + ...45_create_personal_access_tokens_table.php | 33 + thanasoft-back/routes/api.php | 2 + thanasoft-front/.env | 4 +- thanasoft-front/.eslintignore | 3 - thanasoft-front/.eslintrc.js | 40 +- thanasoft-front/AUTH_SETUP.md | 167 ++++ thanasoft-front/package-lock.json | 890 ++++++++++++++---- thanasoft-front/package.json | 35 +- thanasoft-front/public/index.html | 3 +- thanasoft-front/src/App.vue | 52 +- .../soft-ui-dashboard/custom/_styles.scss | 2 + .../soft-ui-dashboard/custom/_variables.scss | 3 + thanasoft-front/src/components/HelloWorld.vue | 108 +++ .../components/Organism/LoginPresentation.vue | 15 + .../components/molecules/auth/LoginForm.vue | 115 +++ .../molecules/auth/SocialMedia.buttons.vue | 67 ++ .../components/templates/LoginTemplate.vue | 34 + .../src/examples/Navbars/Navbar.vue | 28 +- .../src/examples/PageLayout/Navbar.vue | 3 +- .../src/examples/Sidenav/SidenavCollapse.vue | 16 +- .../examples/Sidenav/SidenavCollapseItem.vue | 10 +- .../src/examples/Sidenav/SidenavList.vue | 6 +- thanasoft-front/src/main.ts | 2 + thanasoft-front/src/plugins/pinia.ts | 5 + thanasoft-front/src/router/index.js | 86 +- thanasoft-front/src/services/auth.ts | 92 ++ thanasoft-front/src/services/http.ts | 66 ++ thanasoft-front/src/services/index.ts | 2 + thanasoft-front/src/shims-vue.d.ts | 42 +- thanasoft-front/src/store/index.js | 6 +- thanasoft-front/src/stores/auth.ts | 86 ++ thanasoft-front/src/types/user.ts | 8 - thanasoft-front/src/views/Home.vue | 17 +- .../applications/analytics/Analytics.vue | 66 +- .../src/views/auth/signin/Basic.vue | 62 +- .../src/views/auth/signin/Cover.vue | 58 +- .../src/views/dashboards/Automotive.vue | 28 +- .../src/views/dashboards/Default.vue | 2 +- .../src/views/dashboards/SmartHome.vue | 28 +- .../src/views/dashboards/vr/VRInfo.vue | 30 +- .../src/views/ecommerce/ProductPage.vue | 12 +- .../src/views/ecommerce/ProductsList.vue | 6 +- .../src/views/ecommerce/overview/Overview.vue | 66 +- thanasoft-front/src/views/pages/Login.vue | 149 +++ thanasoft-front/src/views/pages/Register.vue | 153 +++ .../src/views/pages/profile/Overview.vue | 58 +- .../src/views/pages/profile/Teams.vue | 76 +- thanasoft-front/tsconfig.json | 38 +- thanasoft-front/vue.config.js | 24 - 54 files changed, 2408 insertions(+), 597 deletions(-) create mode 100644 thanasoft-back/config/cors.php create mode 100644 thanasoft-back/database/migrations/2025_10_06_145345_create_personal_access_tokens_table.php delete mode 100644 thanasoft-front/.eslintignore create mode 100644 thanasoft-front/AUTH_SETUP.md create mode 100644 thanasoft-front/src/components/HelloWorld.vue create mode 100644 thanasoft-front/src/components/Organism/LoginPresentation.vue create mode 100644 thanasoft-front/src/components/molecules/auth/LoginForm.vue create mode 100644 thanasoft-front/src/components/molecules/auth/SocialMedia.buttons.vue create mode 100644 thanasoft-front/src/components/templates/LoginTemplate.vue create mode 100644 thanasoft-front/src/plugins/pinia.ts create mode 100644 thanasoft-front/src/services/auth.ts create mode 100644 thanasoft-front/src/services/http.ts create mode 100644 thanasoft-front/src/services/index.ts create mode 100644 thanasoft-front/src/stores/auth.ts delete mode 100644 thanasoft-front/src/types/user.ts create mode 100644 thanasoft-front/src/views/pages/Login.vue create mode 100644 thanasoft-front/src/views/pages/Register.vue delete mode 100644 thanasoft-front/vue.config.js diff --git a/thanasoft-back/app/Models/User.php b/thanasoft-back/app/Models/User.php index 749c7b7..91135d7 100644 --- a/thanasoft-back/app/Models/User.php +++ b/thanasoft-back/app/Models/User.php @@ -6,11 +6,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { /** @use HasFactory<\Database\Factories\UserFactory> */ - use HasFactory, Notifiable; + use HasApiTokens, HasFactory, Notifiable; /** * The attributes that are mass assignable. diff --git a/thanasoft-back/bootstrap/app.php b/thanasoft-back/bootstrap/app.php index c183276..c3928c5 100644 --- a/thanasoft-back/bootstrap/app.php +++ b/thanasoft-back/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', + api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) diff --git a/thanasoft-back/composer.json b/thanasoft-back/composer.json index 9089a07..34284d9 100644 --- a/thanasoft-back/composer.json +++ b/thanasoft-back/composer.json @@ -11,6 +11,7 @@ "require": { "php": "^8.2", "laravel/framework": "^12.0", + "laravel/sanctum": "^4.2", "laravel/tinker": "^2.10.1" }, "require-dev": { @@ -75,4 +76,4 @@ }, "minimum-stability": "stable", "prefer-stable": true -} \ No newline at end of file +} diff --git a/thanasoft-back/composer.lock b/thanasoft-back/composer.lock index 89a6721..3089aab 100644 --- a/thanasoft-back/composer.lock +++ b/thanasoft-back/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c514d8f7b9fc5970bdd94287905ef584", + "content-hash": "8f387a0734f3bf879214e4aa2fca6e2f", "packages": [ { "name": "brick/math", @@ -1332,6 +1332,70 @@ }, "time": "2025-09-19T13:47:56+00:00" }, + { + "name": "laravel/sanctum", + "version": "v4.2.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/sanctum.git", + "reference": "fd6df4f79f48a72992e8d29a9c0ee25422a0d677" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/sanctum/zipball/fd6df4f79f48a72992e8d29a9c0ee25422a0d677", + "reference": "fd6df4f79f48a72992e8d29a9c0ee25422a0d677", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^11.0|^12.0", + "illuminate/contracts": "^11.0|^12.0", + "illuminate/database": "^11.0|^12.0", + "illuminate/support": "^11.0|^12.0", + "php": "^8.2", + "symfony/console": "^7.0" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "orchestra/testbench": "^9.0|^10.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^11.3" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Sanctum\\SanctumServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Sanctum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.", + "keywords": [ + "auth", + "laravel", + "sanctum" + ], + "support": { + "issues": "https://github.com/laravel/sanctum/issues", + "source": "https://github.com/laravel/sanctum" + }, + "time": "2025-07-09T19:45:24+00:00" + }, { "name": "laravel/serializable-closure", "version": "v2.0.5", diff --git a/thanasoft-back/config/cors.php b/thanasoft-back/config/cors.php new file mode 100644 index 0000000..97f424a --- /dev/null +++ b/thanasoft-back/config/cors.php @@ -0,0 +1,28 @@ + ['api/*', 'sanctum/csrf-cookie'], + + // Allow all HTTP methods for simplicity in dev + 'allowed_methods' => ['*'], + + // IMPORTANT: Do NOT use '*' when sending credentials. List explicit origins. + // Set FRONTEND_URL in .env to override the default if needed. + 'allowed_origins' => [env('FRONTEND_URL', 'http://localhost:8080')], + + // Alternatively, use patterns (kept empty for clarity) + 'allowed_origins_patterns' => [], + + // Headers the client may send + 'allowed_headers' => ['*'], + + // Headers exposed to the browser + 'exposed_headers' => [], + + // Preflight cache duration (in seconds) + 'max_age' => 0, + + // Must be true if the browser sends cookies or Authorization with withCredentials + 'supports_credentials' => true, +]; diff --git a/thanasoft-back/database/migrations/2025_10_06_145345_create_personal_access_tokens_table.php b/thanasoft-back/database/migrations/2025_10_06_145345_create_personal_access_tokens_table.php new file mode 100644 index 0000000..40ff706 --- /dev/null +++ b/thanasoft-back/database/migrations/2025_10_06_145345_create_personal_access_tokens_table.php @@ -0,0 +1,33 @@ +id(); + $table->morphs('tokenable'); + $table->text('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + $table->timestamp('last_used_at')->nullable(); + $table->timestamp('expires_at')->nullable()->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('personal_access_tokens'); + } +}; diff --git a/thanasoft-back/routes/api.php b/thanasoft-back/routes/api.php index 0fe4136..62d4673 100644 --- a/thanasoft-back/routes/api.php +++ b/thanasoft-back/routes/api.php @@ -19,6 +19,8 @@ Route::prefix('auth')->group(function () { Route::middleware('auth:sanctum')->group(function () { Route::get('/me', [AuthController::class, 'me']); + // Alias to support clients calling /api/auth/user + Route::get('/user', [AuthController::class, 'me']); Route::post('/logout', [AuthController::class, 'logout']); Route::post('/logout-all', [AuthController::class, 'logoutAll']); }); diff --git a/thanasoft-front/.env b/thanasoft-front/.env index bc9086d..18d6ec6 100644 --- a/thanasoft-front/.env +++ b/thanasoft-front/.env @@ -1 +1,3 @@ -NODE_ENV= \ No newline at end of file +# API base URL for axios (used by src/services/http.ts) +# For Laravel Sanctum on local dev (default Laravel port): +VUE_APP_API_BASE_URL=http://localhost:8000 diff --git a/thanasoft-front/.eslintignore b/thanasoft-front/.eslintignore deleted file mode 100644 index f2c1f41..0000000 --- a/thanasoft-front/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -dist/ -node_modules/ -public/ diff --git a/thanasoft-front/.eslintrc.js b/thanasoft-front/.eslintrc.js index d9f53ce..1a4cb3a 100644 --- a/thanasoft-front/.eslintrc.js +++ b/thanasoft-front/.eslintrc.js @@ -1,19 +1,47 @@ module.exports = { root: true, + env: { - node: true, browser: true, + node: true, es6: true, }, + extends: [ - 'plugin:vue/vue3-essential', - '@vue/prettier', + "eslint:recommended", + "plugin:vue/vue3-recommended", + "@vue/typescript", + "@vue/prettier", ], + parserOptions: { - parser: 'babel-eslint', + parser: "@typescript-eslint/parser", + ecmaVersion: 2020, + sourceType: "module", }, + rules: { - 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', - 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', + // Relax console/debugger in development + "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", + "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", + }, + + ignorePatterns: [ + "node_modules/", + "dist/", + "public/*.min.js", + "public/**/*.min.js", + ], + + // Disable base no-unused-vars in .vue files to avoid false positives with + diff --git a/thanasoft-front/src/App.vue b/thanasoft-front/src/App.vue index 91db55e..d6f8de6 100644 --- a/thanasoft-front/src/App.vue +++ b/thanasoft-front/src/App.vue @@ -1,26 +1,34 @@ + + + diff --git a/thanasoft-front/src/components/Organism/LoginPresentation.vue b/thanasoft-front/src/components/Organism/LoginPresentation.vue new file mode 100644 index 0000000..81835f7 --- /dev/null +++ b/thanasoft-front/src/components/Organism/LoginPresentation.vue @@ -0,0 +1,15 @@ + + diff --git a/thanasoft-front/src/components/molecules/auth/LoginForm.vue b/thanasoft-front/src/components/molecules/auth/LoginForm.vue new file mode 100644 index 0000000..eb5358e --- /dev/null +++ b/thanasoft-front/src/components/molecules/auth/LoginForm.vue @@ -0,0 +1,115 @@ + + diff --git a/thanasoft-front/src/components/molecules/auth/SocialMedia.buttons.vue b/thanasoft-front/src/components/molecules/auth/SocialMedia.buttons.vue new file mode 100644 index 0000000..946cac9 --- /dev/null +++ b/thanasoft-front/src/components/molecules/auth/SocialMedia.buttons.vue @@ -0,0 +1,67 @@ + diff --git a/thanasoft-front/src/components/templates/LoginTemplate.vue b/thanasoft-front/src/components/templates/LoginTemplate.vue new file mode 100644 index 0000000..4f4b2bb --- /dev/null +++ b/thanasoft-front/src/components/templates/LoginTemplate.vue @@ -0,0 +1,34 @@ + diff --git a/thanasoft-front/src/examples/Navbars/Navbar.vue b/thanasoft-front/src/examples/Navbars/Navbar.vue index ba63587..a1a6e51 100644 --- a/thanasoft-front/src/examples/Navbars/Navbar.vue +++ b/thanasoft-front/src/examples/Navbars/Navbar.vue @@ -55,16 +55,16 @@