-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add read me docs for all methods
- Loading branch information
1 parent
abf2ee4
commit 30e06b5
Showing
2 changed files
with
168 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,51 +45,188 @@ npx nuxi module add auth-laravel | |
```bash | ||
.env | ||
LARAVEL_BASE_URL='http://localhost:8000' | ||
// other config options listed below | ||
|
||
or | ||
|
||
nuxt.config.ts | ||
laravel { | ||
baseUrl: 'http://localhost:8000' | ||
// other config options listed below | ||
} | ||
``` | ||
|
||
That's it! You can now use Nuxt Laravel Auth in your Nuxt app ✨ | ||
|
||
See below for a full list of config setting that are acepted by Nuxt Laravel auth | ||
|
||
## Coming Soon | ||
## Using the Module | ||
|
||
Here is a list of all of the built in composeables for this module: | ||
|
||
### useLaravelAuth | ||
|
||
Login with email method | ||
|
||
```ts | ||
const { handleLoginWithEmail } = useLaravelAuth(); | ||
const handleFormSubmit = () => { | ||
handleLoginWithEmail({ | ||
email: "[email protected]", | ||
password: "mypassword", | ||
remember: false, | ||
}); | ||
}; | ||
``` | ||
|
||
Register with email method | ||
|
||
```ts | ||
const { handleRegisterWithEmail } = useLaravelAuth(); | ||
const handleFormSubmit = () => { | ||
handleRegisterWithEmail({ | ||
name: "John Doe", | ||
email: "[email protected]", | ||
password: "mypassword", | ||
password_confirmation: "mypassword", | ||
}); | ||
}; | ||
``` | ||
|
||
Logout from account method | ||
|
||
```ts | ||
const { handleLogout } = useLaravelAuth(); | ||
const handleLogoutButtonClick = () => { | ||
handleLogout(); | ||
}; | ||
``` | ||
|
||
A full feature guide and docs are coming very soon... | ||
Forgot Password method | ||
|
||
```ts | ||
const { handleForgotPassword } = useLaravelAuth(); | ||
const handleFormSubmit = () => { | ||
handleRegisterWithEmail({ | ||
email: "[email protected]", | ||
}); | ||
}; | ||
``` | ||
|
||
Reset Password Method | ||
|
||
```ts | ||
const { handleResetPassword } = useLaravelAuth(); | ||
const handleFormSubmit = () => { | ||
handleResetPassword({ | ||
token: route.params.token, | ||
email: route.query.email, | ||
password: "mypassword", | ||
password_confirmation: "mypassword", | ||
}); | ||
}; | ||
``` | ||
|
||
Social Login | ||
|
||
```ts | ||
const { handleSocialAuth } = useLaravelAuth(); | ||
const handleFormSubmit = () => { | ||
handleSocialAuth("google"); | ||
}; | ||
``` | ||
|
||
### useLaravelUser | ||
|
||
Get the current user | ||
|
||
```ts | ||
const user = useLaravelUser<T>(); // We can pass T as a custom user type when retuning extra data from Laravel | ||
``` | ||
|
||
### useLaravelRequest && useAsyncLaravelRequest | ||
|
||
Basic Laravel request example | ||
|
||
```ts | ||
const { data } = await useLaravelRequest<LaravelResponse<Team[]>>( | ||
"/api/teams", // endpoint | ||
{} // fetch options | ||
); | ||
``` | ||
|
||
Async Laravel request example - using useAsyncData under the hood | ||
|
||
```ts | ||
const { data, laravelErrors, laravelMessage, error, status, refresh } = | ||
await useAsyncLaravelRequest<LaravelResponse<Team[]>>( | ||
"/api/teams", // endpoint | ||
"test", // key | ||
{} // fetch options | ||
); | ||
``` | ||
|
||
### useLaravelPagination | ||
|
||
```ts | ||
const pages = useLaravelPagination(total: number, perPage: number, currentPage: number) | ||
``` | ||
|
||
## Configuring the module | ||
|
||
Here is a list of all the options that can be passed into the Nuxt Config or via the .env file. | ||
|
||
| Nuxt Config | env | type | default | Required | | ||
| ------------------------------ | -------------------------------- | ------ | -------------------- | -------- | | ||
| baseUrl | LARAVEL_URL | string | | yes | | ||
| CSRFurl | LARAVEL_CSRF_URL | string | /sanctum/csrf-cookie | no | | ||
| cookieToken | LARAVEL_COOKIE_TOKEN | string | XSRF-TOKEN | no | | ||
| requestToken | LARAVEL_REQUEST_TOKEN | string | X-XSRF-TOKEN | no | | ||
| authBaseUrl | LARAVEL_AUTH_URL | string | baseUrl | no | | ||
| authCSRFurl | LARAVEL_AUTH_CSRF_URL | string | CSRFurl | no | | ||
| authCookieToken | LARAVEL_AUTH_COOKIE_TOKEN | string | cookieToken | no | | ||
| authRequestToken | LARAVEL_AUTH_REQUEST_TOKEN | string | requestToken | no | | ||
| authLoginUrl | LARAVEL_AUTH_LOGIN_URL | string | /login | no | | ||
| authRegisterUrl | LARAVEL_AUTH_REGISTER_URL | string | /register | no | | ||
| authLogoutUrl | LARAVEL_AUTH_LOGOUT_URL | string | /logout | no | | ||
| authForgotPasswordUrl | LARAVEL_AUTH_FORGOT_PASSWORD_URL | string | /forgot-password | no | | ||
| authResetPasswordUrl | LARAVEL_AUTH_RESET_PASSWORD_URL | string | /reset-password | no | | ||
| authVerifyUrl | LARAVEL_AUTH_VERIFY_URL | string | /email/verify | no | | ||
| authProviders.authGoogleUrl | LARAVEL_AUTH_GOOGLE_URL | string | | no | | ||
| authProviders.authAppleUrl | LARAVEL_AUTH_APPLE_URL | string | | no | | ||
| authProviders.authFacebookUrl | LARAVEL_AUTH_FACEBOOK_URL | string | | no | | ||
| authProviders.authTwitterUrl | LARAVEL_AUTH_TWITTER_URL | string | | no | | ||
| authProviders.authLinkedinUrl | LARAVEL_AUTH_LINKEDIN_URL | string | | no | | ||
| authProviders.authGithubUrl | LARAVEL_AUTH_GITHUB_URL | string | | no | | ||
| authProviders.authGitlabUrl | LARAVEL_AUTH_GITLAB_URL | string | | no | | ||
| authProviders.authBitbucketUrl | LARAVEL_AUTH_BITBUCKET_URL | string | | no | | ||
| authProviders.authSlackUrl | LARAVEL_AUTH_SLACK_URL | string | | no | | ||
|
||
## Contribution | ||
|
||
<details> | ||
<summary>Local development</summary> | ||
|
||
```bash | ||
# Install dependencies | ||
npm install | ||
|
||
# Generate type stubs | ||
npm run dev:prepare | ||
|
||
# Develop with the playground | ||
npm run dev | ||
|
||
# Build the playground | ||
npm run dev:build | ||
|
||
# Run ESLint | ||
npm run lint | ||
|
||
# Run Vitest | ||
npm run test | ||
npm run test:watch | ||
|
||
# Release new version | ||
npm run release | ||
``` | ||
|
||
</details> | ||
```bash | ||
# Install dependencies | ||
npm install | ||
|
||
# Generate type stubs | ||
npm run dev:prepare | ||
|
||
# Develop with the playground | ||
npm run dev | ||
|
||
# Build the playground | ||
npm run dev:build | ||
|
||
# Run ESLint | ||
npm run lint | ||
|
||
# Run Vitest | ||
npm run test | ||
npm run test:watch | ||
|
||
# Release new version | ||
npm run release | ||
``` | ||
|
||
<!-- Badges --> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters