mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 11:42:05 +00:00
fix(useapplelogin): jwt errors
This commit is contained in:
parent
b86887e111
commit
2713c8b46d
1 changed files with 10 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { useCallback, useRef } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
import jwtDecode from 'jwt-decode';
|
import { jwtDecode, JwtPayload } from 'jwt-decode';
|
||||||
|
|
||||||
type AppleLoginResponse = {
|
type AppleLoginResponse = {
|
||||||
token: string;
|
token: string;
|
||||||
|
|
@ -20,6 +20,12 @@ type AppleSignInResponse = {
|
||||||
lastName?: string;
|
lastName?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CustomJWTPayload = JwtPayload & {
|
||||||
|
sub: string;
|
||||||
|
email?: string;
|
||||||
|
};
|
||||||
|
|
||||||
const CLIENT_ID = 'com.stremio.services';
|
const CLIENT_ID = 'com.stremio.services';
|
||||||
|
|
||||||
const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
|
const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
|
||||||
|
|
@ -49,14 +55,14 @@ const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
|
||||||
|
|
||||||
window.AppleID.auth.signIn().then((response: AppleSignInResponse) => {
|
window.AppleID.auth.signIn().then((response: AppleSignInResponse) => {
|
||||||
if (response.authorization) {
|
if (response.authorization) {
|
||||||
console.log('Apple Sign-In response:', response); // eslint-disable-line no-console
|
console.log('Apple Sign-In response:', response.authorization); // eslint-disable-line no-console
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const idToken = response.authorization.id_token;
|
const idToken = response.authorization.id_token;
|
||||||
const email = response.email || '';
|
const payload: CustomJWTPayload = jwtDecode(idToken);
|
||||||
const payload = jwtDecode.jwtDecode(response.authorization.id_token);
|
|
||||||
console.log('Decoded id_token:', payload); // eslint-disable-line no-console
|
console.log('Decoded id_token:', payload); // eslint-disable-line no-console
|
||||||
const sub = payload.sub;
|
const sub = payload.sub;
|
||||||
|
const email = payload.email ?? response.email ?? '';
|
||||||
|
|
||||||
let name = '';
|
let name = '';
|
||||||
if (response.fullName) {
|
if (response.fullName) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue