# All files / atlas/src/components/Auth Login.tsx

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147

     // import { StackNavigationProp } from "@react-navigation/stack";
    // import axios from "axios";
    // import { loadAsync, makeRedirectUri, ResponseType } from "expo-auth-session";
    // import * as WebBrowser from 'expo-web-browser';
    // import { Formik } from 'formik';
    // import jwt_decode from "jwt-decode";
    // import React, { useState } from "react";
    // import { StyleSheet, Text, TextInput, View } from "react-native";
    // import { API_URL, colors } from "../../globals";
    // import { AuthStackParamList } from "../../navigation/UnauthorizedNavigator";
    // import AuthLayout from "./AuthLayout";
    // import { PrimaryButton } from "./Buttons";

    // export type LoginNavigationProp = StackNavigationProp<AuthStackParamList, "Login">

    // export type LoginProps = {
    //     navigation: LoginNavigationProp;
    // }

    // export type LoginFormValues = {
    //     username?: string,
    //     password?: string
    // }

    // const issuer = API_URL + "/o";

    // const discovery = {
    //     authorizationEndpoint: issuer + "/authorize",
    //     tokenEndpoint: issuer + "/token",
    //     revocationEndpoint: issuer + "/revoke",
    //   };

    // WebBrowser.maybeCompleteAuthSession();

    // const Login: React.FC<LoginProps> = ({navigation}) => {
    //     const [formValues, setFormValues] = useState<LoginFormValues>({username: "", password: ""});
    //     const [errors, setErrors] = useState<LoginFormValues>({username: '', password: ''});

    //     const validate = (values: LoginFormValues) => {
    //         const errors: LoginFormValues = {};
    //         if (!values.username) {
    //             errors.username = 'Email is required';
    //         }
    //         if (!values.password) {
    //             errors.password = 'Password is required';
    //         }
    //         return errors;
    //     }

    //     const redirectUri = makeRedirectUri({
    //         scheme: 'atlas.mobile',
    //         path: 'callback',
    //         useProxy: false
    //       });

    //     const submitLogin = async (formValues: any) => {
    //         const request = await loadAsync({
    //             clientId: "atlas.mobile",
    //             responseType: ResponseType.Code,
    //             usePKCE: true,
    //             redirectUri,
    //             scopes: ['openid'],
    //         }, discovery)

    //         const response = await request.promptAsync(discovery);
    //         if (response.type == "success" && request.codeVerifier) {
    //             const tokenData = new URLSearchParams();
    //             tokenData.append('grant_type', 'authorization_code');
    //             tokenData.append('client_id', 'atlas.mobile');
    //             tokenData.append('code', response.params.code);
    //             tokenData.append('redirect_uri', request.redirectUri);
    //             tokenData.append('code_verifier', request.codeVerifier);
    //             try {
    //                 const response = await axios.post(API_URL + `/o/token/`, tokenData, {
    //                     headers: {
    //                         'Content-Type': "application/x-www-form-urlencoded"
    //                     },
    //                 });

    //                 const tokenResponse = response.data;
    //                 const idToken = jwt_decode(tokenResponse.id_token);
    //                 const accessToken = tokenResponse.access_token;
    //                 const refreshToken = tokenResponse.refresh_token;

    //             } catch (error) {
    //                 console.log(error.response);
    //             }
    //         }
    //     }

    //     return (
    //     <AuthLayout>
    //         <View style={styles.titleContainer}>
    //           <Text style={styles.title} >Welcome back!</Text>
    //           <Text style={styles.subtitle} >Lets get you signed in.</Text>
    //         </View>
    //         <Formik initialValues={{username: '', password: ''}} onSubmit={values => submitLogin(values)} validate={validate}>
    //             {({handleChange, handleSubmit, values, errors, touched}) => (
    //                 <View style={styles.formContainer}>
    //                     <TextInput style={styles.formInput} onChangeText={handleChange('username')} placeholder="Username or email" value={values.username}/>
    //                     {errors.username && touched.username ? <Text style={styles.error}>{errors.username}</Text> : null}
    //                     <TextInput style={styles.formInput} onChangeText={handleChange('password')} placeholder="Password" value={values.password}/>
    //                     {errors.password && touched.password ? <Text style={styles.error}>{errors.password}</Text> : null}
    //                     <PrimaryButton text="Submit" style={styles.submitBtn} onPress={handleSubmit as any} />
    //                 </View>
    //             )}
    //         </Formik>
    //     </AuthLayout>)
    // }

    // const styles = StyleSheet.create({
    //     titleContainer: {
    //         paddingTop: 100,

    //     },
    //     title: {
    //         color: 'white',
    //         fontSize: 20,
    //         marginBottom: 20
    //     },
    //     subtitle: {
    //         color: 'white',
    //         fontSize: 15,
    //     },
    //     formContainer: {
    //         width: '100%',
    //         marginTop: 30,
    //     },
    //     formInput: {
    //         backgroundColor: 'white',
    //         marginBottom: 10,
    //         height: 50,
    //         borderRadius: 25,
    //         paddingLeft: 20
    //     },
    //     submitBtn: {
    //         marginTop: 30
    //     },
    //     error: {
    //         color: colors.red,
    //         alignSelf: "flex-end",
    //         marginBottom: 10
    //     }
    // })

    // export default Login