Skip to content

Commit b9aab84

Browse files
committed
Update README.MD
1 parent bab9112 commit b9aab84

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The goal of the project is to create a template for development on Laravel and N
1717
- [Installation](#installation)
1818
- [Standalone](#standalone)
1919
- [Docker Deploy (Laravel Sail)](#docker-deploy-laravel-sail)
20+
- [Auth Guard Switch](#auth-guard-switch)
2021
- [Upgrade](#upgrade)
2122
- [Usage](#usage)
2223
- [Fetch wrapper](#fetch-wrapper)
@@ -36,7 +37,7 @@ The goal of the project is to create a template for development on Laravel and N
3637
- [**Laravel 12**](https://laravel.com/docs/12.x) and [**Nuxt 4**](https://nuxt.com/)
3738
- [**Laravel Octane**](https://laravel.com/docs/12.x/octane) supercharges your application's performance by serving your application using high-powered application servers.
3839
- [**Laravel Telescope**](https://laravel.com/docs/12.x/telescope) provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.
39-
- [**Laravel Sanctum**](https://laravel.com/docs/12.x/sanctum) Token-based authorization is compatible with **SSR** and **CSR**
40+
- [**Laravel Sanctum**](https://laravel.com/docs/12.x/sanctum) Token/Session-based authorization is compatible with **SSR** and **CSR**
4041
- [**Laravel Socialite**](https://laravel.com/docs/12.x/socialite) OAuth providers
4142
- [**Laravel Sail**](https://laravel.com/docs/12.x/sail) Light-weight command-line interface for interacting with Laravel's default Docker development environment.
4243
- [**Spatie Laravel Permissions**](https://spatie.be/docs/laravel-permission/v6/introduction) This package allows you to manage user permissions and roles in a database.
@@ -89,6 +90,14 @@ To make sure this is always available, you may add this to your shell configurat
8990

9091
> Read the full [Laravel Sail](https://laravel.com/docs/12.x/sail) documentation to get the best user experience
9192
93+
### Auth Guard Switch
94+
95+
You can switch the authentication guard between **Token** and **Session** using the following command:
96+
97+
```shell
98+
php artisan auth:switch
99+
```
100+
92101
## Upgrade
93102

94103
Standalone:
@@ -117,7 +126,6 @@ Additionally, `$http` predefines a base url, authorization headers, and proxy IP
117126
For example, the code for authorizing a user by email and password:
118127
```vue
119128
<script lang="ts" setup>
120-
const nuxtApp = useNuxtApp();
121129
const router = useRouter();
122130
const auth = useAuthStore();
123131
const form = templateRef("form");
@@ -136,9 +144,7 @@ const { refresh: onSubmit, status } = useHttp("login", {
136144
if (response?.status === 422) {
137145
form.value.setErrors(response._data?.errors);
138146
} else if (response._data?.ok) {
139-
nuxtApp.$token.value = response._data.token;
140-
141-
await auth.fetchUser();
147+
await auth.login(response._data.token ?? null);
142148
await router.push("/");
143149
}
144150
}
@@ -182,8 +188,10 @@ const loading = computed(() => status.value === "pending");
182188
Data returned by **useAuthStore**:
183189
* `logged`: Boolean, whether the user is authorized
184190
* `user`: User object, user stored in pinia store
185-
* `logout`: Function, remove local data and call API to remove token
191+
* `fetchCsrf`: Function, fetch csrf token
186192
* `fetchUser`: Function, fetch user data
193+
* `login`: Function, login user by token/session
194+
* `logout`: Function, remove local data and call API to remove token/session
187195
* `hasRole`: Function, checks the role
188196

189197
### Nuxt Middleware

0 commit comments

Comments
 (0)