mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-03-22 09:27:49 -04:00
Handle cookies in auth codepath
This commit is contained in:
parent
0c890e7d49
commit
e6f8a223df
15
auth/main.go
15
auth/main.go
@ -171,14 +171,25 @@ func (h *Handler) TokenToJwt(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
jwt = &token
|
||||
} else {
|
||||
auth := c.Request().Header.Get("Authorization")
|
||||
var token string
|
||||
|
||||
if auth == "" || !strings.HasPrefix(auth, "Bearer ") {
|
||||
if auth == "" {
|
||||
cookie, _ := c.Request().Cookie("X-Bearer")
|
||||
if cookie != nil {
|
||||
token = cookie.Value
|
||||
}
|
||||
} else if strings.HasPrefix(auth, "Bearer ") {
|
||||
token = auth[len("Bearer "):]
|
||||
} else if auth != "" {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid bearer format.")
|
||||
}
|
||||
|
||||
if token == "" {
|
||||
jwt = h.createGuestJwt()
|
||||
if jwt == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Guests not allowed.")
|
||||
}
|
||||
} else {
|
||||
token := auth[len("Bearer "):]
|
||||
// this is only used to check if it is a session token or a jwt
|
||||
_, err := base64.RawURLEncoding.DecodeString(token)
|
||||
if err != nil {
|
||||
|
||||
@ -3,7 +3,7 @@ import { createMMKV, useMMKVString } from "react-native-mmkv";
|
||||
import type { ZodType, z } from "zod/v4";
|
||||
import { getServerData } from "~/utils";
|
||||
|
||||
export const storage = createMMKV();
|
||||
export const storage = createMMKV({ id: "kyoo-v5" });
|
||||
|
||||
function toBase64(utf8: string) {
|
||||
if (typeof window !== "undefined") return window.btoa(utf8);
|
||||
@ -35,7 +35,6 @@ export const setCookie = (
|
||||
|
||||
export const readCookie = <T extends ZodType>(key: string, parser: T) => {
|
||||
const cookies = getServerData("cookies");
|
||||
console.log("cookies", cookies);
|
||||
const decodedCookie = decodeURIComponent(cookies);
|
||||
const ca = decodedCookie.split(";");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user