Clean redux
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
b94cc83dbb
commit
559f299aeb
@ -1,14 +1,13 @@
|
|||||||
import Music from "../Music";
|
import Music from "../Music";
|
||||||
|
|
||||||
export default class MusicMapper {
|
export default class MusicMapper {
|
||||||
static mapFromSpotifyTrack(jsonMusic: any): Music {
|
static toModel(music: any): Music {
|
||||||
const music = new Music(
|
return new Music(
|
||||||
jsonMusic.id,
|
music.id,
|
||||||
jsonMusic.name,
|
music.name,
|
||||||
jsonMusic.artists[0].name,
|
music.artists[0].name,
|
||||||
jsonMusic.album.images[0].url,
|
music.album.images[0].url,
|
||||||
jsonMusic.preview_url
|
music.preview_url
|
||||||
);
|
);
|
||||||
return music;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
export const userTypes = {
|
export const userTypes = {
|
||||||
|
RESTORE_TOKEN: "RESTORE_TOKEN",
|
||||||
LOGIN: 'LOGIN',
|
LOGIN: 'LOGIN',
|
||||||
SIGNUP: 'SIGNUP',
|
SIGNUP: 'SIGNUP',
|
||||||
|
USER_LOGOUT: 'USER_LOGOUT',
|
||||||
SAVE_SPOTIFY: 'SAVE_SPOTIFY',
|
SAVE_SPOTIFY: 'SAVE_SPOTIFY',
|
||||||
UPDATE_USER: 'UPDATE_USER',
|
UPDATE_USER: 'UPDATE_USER',
|
||||||
UPDATE_PROFILE_PICTURE: 'UPDATE_PROFILE_PICTURE',
|
ERROR_LOGIN: "ERROR_LOGIN",
|
||||||
USER_LOGOUT: 'USER_LOGOUT',
|
ERROR_SIGNUP: "ERROR_SIGNUP",
|
||||||
RESTORE_TOKEN: "RESTORE_TOKEN",
|
DARK_MODE: "DARK_MODE",
|
||||||
CHANGE_MODE: "CHANGE_MODE",
|
ERROR_NETWORK: "ERROR_NETWORK"
|
||||||
CHANGE_ERROR_LOGIN: "CHANGE_ERROR_LOGIN",
|
|
||||||
CHANGE_ERROR_SIGNUP: "CHANGE_ERROR_SIGNUP"
|
|
||||||
}
|
}
|
@ -1,123 +0,0 @@
|
|||||||
import { View, Text, StyleSheet, Button } from 'react-native'
|
|
||||||
import React from 'react'
|
|
||||||
import * as AuthSession from 'expo-auth-session';
|
|
||||||
import * as WebBrowser from 'expo-web-browser';
|
|
||||||
import { makeRedirectUri, useAuthRequest } from 'expo-auth-session';
|
|
||||||
import { Buffer } from 'buffer';
|
|
||||||
import * as SecureStore from 'expo-secure-store';
|
|
||||||
|
|
||||||
WebBrowser.maybeCompleteAuthSession()
|
|
||||||
|
|
||||||
const discovery = {
|
|
||||||
authorizationEndpoint: 'https://accounts.spotify.com/authorize',
|
|
||||||
tokenEndpoint: 'https://accounts.spotify.com/api/token',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Login() {
|
|
||||||
const [request] = useAuthRequest(
|
|
||||||
{
|
|
||||||
responseType: AuthSession.ResponseType.Token,
|
|
||||||
clientId: '1f1e34e4b6ba48b388469dba80202b10',
|
|
||||||
scopes: ['user-read-private', 'user-read-email', 'user-read-playback-state', 'user-read-currently-playing', 'user-read-recently-played', 'playlist-modify-public', 'ugc-image-upload', 'user-modify-playback-state'],
|
|
||||||
usePKCE: false,
|
|
||||||
redirectUri: makeRedirectUri({
|
|
||||||
scheme: 'https://auth.expo.io/@anonymous/FLAD-7eafd441-fd6b-4fb6-924c-ec2b0ed5ce6d',
|
|
||||||
useProxy: true
|
|
||||||
})
|
|
||||||
|
|
||||||
},
|
|
||||||
discovery
|
|
||||||
);
|
|
||||||
|
|
||||||
const scopesArr = ['user-read-private', 'user-read-email', 'user-read-playback-state', 'user-read-currently-playing', 'user-read-recently-played', 'playlist-modify-public', 'ugc-image-upload', 'user-modify-playback-state'];
|
|
||||||
const scopes = scopesArr.join(' ');
|
|
||||||
const getAuthorizationCode = async () => {
|
|
||||||
try {
|
|
||||||
const redirectUrl = "https://auth.expo.io/@anonymous/FLAD-7eafd441-fd6b-4fb6-924c-ec2b0ed5ce6d"
|
|
||||||
const result = await AuthSession.startAsync({
|
|
||||||
authUrl:
|
|
||||||
'https://accounts.spotify.com/authorize' +
|
|
||||||
'?response_type=code' +
|
|
||||||
'&client_id=' +
|
|
||||||
"1f1e34e4b6ba48b388469dba80202b10" +
|
|
||||||
(scopes ? '&scope=' + encodeURIComponent(scopes) : '') +
|
|
||||||
'&redirect_uri=' +
|
|
||||||
encodeURIComponent(redirectUrl),
|
|
||||||
})
|
|
||||||
return result.params.code;
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const getTokens = async () => {
|
|
||||||
try {
|
|
||||||
const authorizationCode = await getAuthorizationCode()
|
|
||||||
await fetch('https://accounts.spotify.com/api/token', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
Authorization: 'Basic ' + (Buffer.from('1f1e34e4b6ba48b388469dba80202b10' + ':' + '779371c6d4994a68b8dd6e84b0873c82').toString('base64')),
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: `grant_type=authorization_code&code=${authorizationCode}&redirect_uri=https://auth.expo.io/@anonymous/FLAD-7eafd441-fd6b-4fb6-924c-ec2b0ed5ce6d`,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<View style={styles.centeredView}>
|
|
||||||
<Text style={styles.textStyle}>Hello flad test logIn</Text>
|
|
||||||
<Button disabled={!request} title="Login"
|
|
||||||
onPress={() => {
|
|
||||||
getTokens()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
centeredView: {
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginTop: 22,
|
|
||||||
},
|
|
||||||
modalView: {
|
|
||||||
margin: 20,
|
|
||||||
backgroundColor: 'white',
|
|
||||||
borderRadius: 20,
|
|
||||||
padding: 35,
|
|
||||||
alignItems: 'center',
|
|
||||||
shadowColor: '#000',
|
|
||||||
shadowOffset: {
|
|
||||||
width: 0,
|
|
||||||
height: 2,
|
|
||||||
},
|
|
||||||
shadowOpacity: 0.25,
|
|
||||||
shadowRadius: 4,
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
alignItems: 'flex-end',
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
button: {
|
|
||||||
borderRadius: 20,
|
|
||||||
padding: 10,
|
|
||||||
elevation: 2,
|
|
||||||
},
|
|
||||||
buttonOpen: {
|
|
||||||
backgroundColor: '#F194FF',
|
|
||||||
},
|
|
||||||
textStyle: {
|
|
||||||
color: 'white',
|
|
||||||
fontWeight: 'bold',
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
close: {
|
|
||||||
alignSelf: 'flex-end',
|
|
||||||
backgroundColor: 'red',
|
|
||||||
justifyContent: 'center'
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
export class UserService {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue