refresh page possibility, clear spotify config

This commit is contained in:
2025-09-02 23:13:12 +02:00
parent 2c3483c26f
commit bfefb89cd8
4 changed files with 29 additions and 8 deletions
+14 -1
View File
@@ -12,7 +12,7 @@ import ThemedButton from "@/src/components/themed/ThemedButton";
import {useRouter} from "expo-router";
export default function SettingsScreen() {
const {token: jwtToken, authenticatedUser, logout} = useAuth();
const {token: jwtToken, authenticatedUser, logout, refreshUser} = useAuth();
const router = useRouter();
const handleAuthSuccess = (token: Token) => {
@@ -26,6 +26,8 @@ export default function SettingsScreen() {
new RestService(jwtToken).updateSelfSpotifyConfig(spotifyConfig).then((result) => {
console.log("Spotify Token gespeichert");
console.log(result);
refreshUser();
});
};
@@ -40,6 +42,17 @@ export default function SettingsScreen() {
jwtToken={jwtToken!}
disabled={!!authenticatedUser?.spotifyConfig}
/>
{!!authenticatedUser?.spotifyConfig && ( <ThemedButton mode={"outlined"} onPress={() => {
const rest = new RestService(jwtToken);
rest.updateSelfSpotifyConfig().then((result) => {
console.log("Spotify Login entfernt");
console.log(result);
refreshUser()
})
}}>
Remove Spotify
</ThemedButton>)}
</View>
<ThemedButton mode={"outlined"} onPress={() => {
console.log("Button pressed");
+3 -2
View File
@@ -26,8 +26,9 @@ export default function ChangePasswordModal() {
}
new RestService(jwtToken).changeSelfPassword(password, confirmPassword).then(
(response) => {
setApiResponse(response);
if (response.success) {
console.log(response);
setApiResponse(response.result);
if (response.result.success) {
// add something here
setPassword("");
setConfirmPassword("");
+7 -1
View File
@@ -16,6 +16,7 @@ type AuthContextType = {
error: AuthError | null;
authenticatedUser: User | null;
loading: boolean;
refreshUser: () => Promise<void>;
};
const AuthContext = createContext<AuthContextType | undefined>(undefined);
@@ -91,8 +92,13 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({children}
setAuthenticatedUser(null);
};
const refreshUser = async () => {
if (!token) return;
await saveUser(token);
};
return (
<AuthContext.Provider value={{isAuthenticated, token, login, logout, error, authenticatedUser, loading}}>
<AuthContext.Provider value={{isAuthenticated, token, login, logout, error, authenticatedUser, loading, refreshUser}}>
{children}
</AuthContext.Provider>
);
+5 -4
View File
@@ -77,8 +77,8 @@ class RestService {
return this.request<User>('GET', '/user/me');
}
async changeSelfPassword(password: string, passwordConfirmation: string): Promise<{ success: boolean; message: string }> {
return this.request<{ success: boolean; message: string }>(
async changeSelfPassword(password: string, passwordConfirmation: string): Promise<{result: { success: boolean; message: string }}> {
return this.request<{result: { success: boolean; message: string } }>(
'PUT',
'/user/me/password',
{password, passwordConfirmation},
@@ -104,11 +104,12 @@ class RestService {
);
}
async updateSelfSpotifyConfig(spotifyConfig: SpotifyConfig): Promise<{ success: boolean; message: string }> {
async updateSelfSpotifyConfig(spotifyConfig?: SpotifyConfig): Promise<{ success: boolean; message: string }> {
const payload = spotifyConfig ?? {};
return this.request<{ success: boolean; message: string }>(
'PUT',
'/user/me/spotify',
spotifyConfig,
payload,
{'Content-Type': 'application/json'}
);
}