Skip to content

Commit 4aff82a

Browse files
committed
docs: update readme and code of conduct
1 parent a232499 commit 4aff82a

File tree

2 files changed

+93
-11
lines changed

2 files changed

+93
-11
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ representative at an online or offline event.
6161

6262
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6363
reported to the community leaders responsible for enforcement at
64-
[INSERT CONTACT METHOD].
64+
info@marcelwagner.dev.
6565
All complaints will be reviewed and investigated promptly and fairly.
6666

6767
All community leaders are obligated to respect the privacy and security of the

README.md

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,113 @@
1-
# react-native-laravel-sanctum
1+
# React Native Laravel Sanctum
22

3-
React Native auth package for Laravel Sanctum integration
3+
React Native auth package for [Laravel Sanctum ](https://laravel.com/docs/10.x/sanctum) integration. While this package is mainly build for Laravel Sanctum APIs, you can use this library for other API-Backends as well.
4+
5+
## Table of Contents
6+
7+
- [Features](#features)
8+
- [Installation](#installation)
9+
- [Basic Usage](#basic-usage)
10+
- [Example App](#example-app)
11+
- [Documentation](#documentation)
12+
- [Contributing](#contributing)
13+
- [License](#license)
14+
15+
## Features
16+
17+
- [x] Login
18+
- [x] Logout
19+
- [x] Get current user
20+
- [x] Check if user is authenticated
21+
- [x] CSRF-Token
422

523
## Installation
624

725
```sh
826
npm install react-native-laravel-sanctum
927
```
28+
### Install native dependencies
29+
As the package relies on `expo-secure-store` you will need to create a new build of your app to use it.
30+
31+
## Basic Usage
1032

11-
## Usage
33+
Wrap your app with `AuthProvider` and pass the `config` object as a prop.
1234

1335
```js
14-
import { multiply } from 'react-native-laravel-sanctum';
36+
import { AuthProvider } from 'react-native-laravel-sanctum';
1537

16-
// ...
1738

18-
const result = await multiply(3, 7);
39+
export default function App() {
40+
const config = {
41+
loginUrl: 'https://your-awesome-domain/api/sanctum/token',
42+
logoutUrl: 'https://your-awesome-domain/api/logout',
43+
userUrl: 'https://your-awesome-domain/api/user',
44+
};
45+
46+
return (
47+
<AuthProvider config={config}>
48+
<View>
49+
...
50+
</View>
51+
</AuthProvider>
52+
);
53+
}
1954
```
2055

56+
You can now use the `useAuth` hook within the AuthProvider to access the auth methods.
57+
58+
```js
59+
import { useAuth } from 'react-native-laravel-sanctum';
60+
61+
export default function Login() {
62+
const { login, getToken, updateUser, setUserIsAuthenticated, isAuthenticated, logout, currentUser } = useAuth();
63+
const [email, setEmail] = useState('');
64+
const [password, setPassword] = useState('');
65+
66+
const handleLogin = async () => {
67+
const tokenObtained = await login(email, password, 'Test-Device');
68+
if (tokenObtained) {
69+
const user = await updateUser();
70+
71+
if (user.id) {
72+
setUserIsAuthenticated(true);
73+
}
74+
}
75+
};
76+
77+
return (
78+
<View>
79+
<Text >You are not logged in.</Text>
80+
<TextInput
81+
onChangeText={text => setEmail(text)}
82+
value={email}
83+
placeholder='Email'
84+
/>
85+
<TextInput
86+
onChangeText={text => setPassword(text)}
87+
value={password}
88+
secureTextEntry
89+
placeholder='Password'
90+
/>
91+
<Pressable onPress={handleLogin}>
92+
<Text>Login</Text>
93+
</Pressable>
94+
</View>
95+
);
96+
}
97+
```
98+
99+
## Example App
100+
101+
You can find the example app [here](https://github.com/Tschucki/react-native-laravel-sanctum-example-app).
102+
103+
## Documentation
104+
105+
You can find the documentation [here](https://github.com/Tschucki/react-native-laravel-sanctum/wiki).
106+
21107
## Contributing
22108

23109
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
24110

25111
## License
26112

27113
MIT
28-
29-
---
30-
31-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

0 commit comments

Comments
 (0)