Closed frankcollins3 closed 11 months ago
exception handler needs empty str because page will have empty string cookie not null if empty. if (userId === null || userId === undefined || userId === ' ') return null [10:22pm]
dodging null && undefined errors but have to handle splitting string when there is cookie
👍 working but that's what happened last time. .split("***") put up a little more fight than .split("id:")
[10:26pm]
just broke again and then wroked again [10:28pm]
export function userIdFromCookie(name) {
console.log('name', name)
if (name === null || name === undefined || name === '') return null
👍 const splitChar = name.split('***')
const userId = splitChar[1]
return userId ? userId : null
// let preregexID = name[0].substring(preIdIndex + 1);
}
can see the *** separating the last number in the set of characters with the preceding string to the left of it.
this particular token which is generated from crpyto.randomBytes() ends in: 👍 "tc***8"
[10:42pm]
👍 if (name[0] !== undefined || name[0] !== undefined || name[0] !== ' ') {
const splitChar = name[0].split('')
const userId = splitChar[1]
return userId ? userId : null
// const splitChar = name[0].split('') || name.split('***')
} else {
console.log("hey were over here")
}
👍 this looks to work most consistently out of every approach but might reopen [11:11pm]
considering storing 2 cookies: 1 for the token one for the userID [11:20pm]
👍 other way approach is insane when given additional thought.. cookie (2) ['token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI…DI2fQ.4UUlswdKJka10G0Ag65o_W7XIpGQXpLBD2SKChLWhnE', '8']
sites say: do you accept "cookies" plural. probably not an array
attempting to do: a "remember me" function that allows user to log in based on their last session
error: splitting token worked and now is returning 't' instead of {userid}
preCookie ['token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI…Q.CgCRWfRU-sJ3dWjIKcr7Eb-mrc85LCW2d5d5qO2Pa08id:7'] LogInOutGoogle2.tsx:56 pageCookie token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiaWF0IjoxNjg5OTAwODM0fQ.CgCRWfRU-sJ3dWjIKcr7Eb-mrc85LCW2d5d5qO2Pa08id:7 cookies.js:25 splitName ['t']0: "t"length: 1[[Prototype]]: Array(0)
heres the function that was originally going to be a lastIndexOf(":") and substring()
last time: splitNameForId: ${token} ${id}
proposed approach: instead of "id:${userId}" ---> ***${userid} I thought this messing up meant that somewhere within the token there was the string of "id" but that isn't so.