@xouteiro/auth_npm 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,78 @@
1
1
  import React, { useState } from 'react';
2
+ import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
2
3
  import { logout } from '../logout';
3
4
 
4
- const boxStyle = {
5
- maxWidth: 350,
6
- margin: '24px auto',
7
- padding: 20,
8
- borderRadius: 10,
9
- boxShadow: '0 2px 12px rgba(0,0,0,0.08)',
10
- background: '#fff',
11
- fontFamily: 'sans-serif',
12
- textAlign: 'center',
13
- };
14
-
15
- const buttonStyle = {
16
- padding: '10px 28px',
17
- borderRadius: 6,
18
- border: 'none',
19
- background: '#0070f3',
20
- color: '#fff',
21
- fontWeight: 600,
22
- fontSize: 16,
23
- cursor: 'pointer',
24
- };
25
-
26
- const messageStyle = (success) => ({
27
- margin: '12px 0',
28
- color: success ? '#0a0' : '#d32f2f',
29
- background: success ? '#eafbe7' : '#fdeaea',
30
- padding: 8,
31
- borderRadius: 6,
32
- textAlign: 'center',
33
- fontSize: 15,
34
- });
35
-
36
5
  export default function LogoutButton({ onLogout }) {
37
- const [message, setMessage] = useState(null);
38
- const [success, setSuccess] = useState(false);
39
-
40
- const handleLogout = async () => {
41
- setMessage(null);
6
+ const [message, setMessage] = useState(null);
7
+ const [success, setSuccess] = useState(false);
8
+
9
+ const handleLogout = async () => {
10
+ setMessage(null);
11
+ setSuccess(false);
12
+ const { error } = await logout();
13
+ if (error) {
14
+ setMessage(error.message || 'Logout failed');
42
15
  setSuccess(false);
43
- const { error } = await logout();
44
- if (error) {
45
- setMessage(error.message || 'Logout failed');
16
+ } else {
17
+ setMessage('Logout successful!');
18
+ setSuccess(true);
19
+ setTimeout(() => {
20
+ setMessage(null);
46
21
  setSuccess(false);
47
- } else {
48
- setMessage('Logout successful!');
49
- setSuccess(true);
50
- setTimeout(() => {
51
- setMessage(null);
52
- setSuccess(false);
53
- if (onLogout) onLogout(); // Call the callback after logout
54
- }, 1500);
55
- }
56
- };
57
-
58
- return (
59
- <div style={boxStyle}>
60
- <button style={buttonStyle} onClick={handleLogout}>Logout</button>
61
- {message && <div style={messageStyle(success)}>{message}</div>}
62
- </div>
63
- );
64
- }
22
+ if (onLogout) onLogout();
23
+ }, 1500);
24
+ }
25
+ };
26
+
27
+ return (
28
+ <View style={styles.box}>
29
+ <TouchableOpacity style={styles.button} onPress={handleLogout}>
30
+ <Text style={styles.buttonText}>Logout</Text>
31
+ </TouchableOpacity>
32
+ {message && (
33
+ <View style={[styles.message, success ? styles.success : styles.error]}>
34
+ <Text style={styles.messageText}>{message}</Text>
35
+ </View>
36
+ )}
37
+ </View>
38
+ );
39
+ }
40
+
41
+ const styles = StyleSheet.create({
42
+ box: {
43
+ maxWidth: 350,
44
+ marginVertical: 24,
45
+ padding: 20,
46
+ borderRadius: 10,
47
+ backgroundColor: '#fff',
48
+ alignSelf: 'center',
49
+ alignItems: 'center',
50
+ },
51
+ button: {
52
+ paddingVertical: 10,
53
+ paddingHorizontal: 28,
54
+ borderRadius: 6,
55
+ backgroundColor: '#0070f3',
56
+ },
57
+ buttonText: {
58
+ color: '#fff',
59
+ fontWeight: '600',
60
+ fontSize: 16,
61
+ },
62
+ message: {
63
+ marginTop: 12,
64
+ padding: 8,
65
+ borderRadius: 6,
66
+ },
67
+ success: {
68
+ backgroundColor: '#eafbe7',
69
+ },
70
+ error: {
71
+ backgroundColor: '#fdeaea',
72
+ },
73
+ messageText: {
74
+ fontSize: 15,
75
+ textAlign: 'center',
76
+ color: '#333',
77
+ },
78
+ });